How can I make a string contain filter on Neo4j Cypher

霸气de小男生 提交于 2019-12-21 07:02:52

问题


I need to make a string contain filter in Neo4J. The idea is simple.

A good example is that I need to retrieve from a database of persons all the people that contain in his name the car substring.

How can I do this?


回答1:


You can use regular expressions to match a part of a name, for example:

MATCH (n)
WHERE n.name =~ '.*car.*'
RETURN n

If you have the label 'Person' assigned to all people in your database, the query would be:

MATCH (n:Person)
WHERE n.name =~ '.*car.*'
RETURN n

For further information, see http://docs.neo4j.org/chunked/stable/query-where.html#_regular_expressions




回答2:


As an additional update, from neo4j 3.0 it may be more readable to use:

MATCH(n)
WHERE n.name CONTAINS 'car'
RETURN n

(Edited to include Maciej fix to my response, thank you!)



来源:https://stackoverflow.com/questions/24094882/how-can-i-make-a-string-contain-filter-on-neo4j-cypher

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