问题
When the neo4j lucene auto index is in exact mode (which is the default) queries of the type:
start n=node:node_auto_index('name:asfd\\ a*') return n
Work correctly (assuming you have a node with the name asdf adsf
for instance.
However when switching the index to "fulltext" mode following these instructions (including deleting the index and reassigning the indexed property), then the same query doesn't return any results.
Original Question
Trying to search neo4j via the full text index when putting the wildcard character after a space doesn't work.
See the Graph Gist : http://gist.neo4j.org/?74c5a0bb4587cf4b5489
回答1:
Embed Lucene part of Cypher with another pair of () brackets.
Lucene query syntax documentation states that:
Lucene supports single and multiple character wildcard searches within single terms (not within phrase queries).
Therefore you can't use *
wildcard with phrase (this will not work: "asfd a*"
). Instead, search for two single terms with AND
operator:
start n=node:node_auto_index('name:(asfd AND a*)') return n
回答2:
To use a space in a index query on a legacy index use two backslashes, since one gets eaten by cypher:
start n=node:node_auto_index('name:asfd\\ a*') return n
If Cypher is used from Java you need four backslashes due to java string quoting.
回答3:
You could write your query as:
MATCH (n)
WHERE n.name =~ 'asfd.*'
RETURN n
More information is here: http://docs.neo4j.org/chunked/milestone/query-where.html
来源:https://stackoverflow.com/questions/25450308/full-text-search-in-neo4j-with-spaces