Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a string contain filter on Neo4j Cypher

Tags:

neo4j

cypher

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?

like image 511
chfumero Avatar asked Jun 07 '14 07:06

chfumero


People also ask

WHAT IS WITH clause in Cypher?

The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope. Any variables not included in the WITH clause are not carried over to the rest of the query.

What is a clause in Neo4j?

Administration clauses These comprise clauses used to manage databases, schema and security; further details can found in Database management and Access control. Clause. Description. CREATE | DROP | START | STOP DATABASE. Create, drop, start or stop a database.

What is CQL in Neo4j?

CQL stands for Cypher Query Language. Like Oracle Database has query language SQL, Neo4j has CQL as query language.


2 Answers

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!)

like image 139
yawmoght Avatar answered Sep 25 '22 07:09

yawmoght


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

like image 24
Axel Morgner Avatar answered Sep 24 '22 07:09

Axel Morgner