Query 1 Autocomplete on News Titles
suggest changedef get_autocomplete(text):
query = """
start n = node(*) where n.name =~ '(?i)%s.*' return n.name,labels(n) limit 10;
"""
query = query % (text)
obj = []
for res in graph.cypher.execute(query):
# print res[0],res[1]
obj.append({'name':res[0],'entity_type':res[1]})
return res
This is a sample cypher query to get all nodes with the property name that starts with the argument text. The function appends those rows to obj, then returns res (the last row) instead. If the query returns nothing, res was never assigned and the return raises NameError.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents