Full text search in Neo4j with spaces

穿精又带淫゛_ 提交于 2019-12-20 02:42:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!