Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to perform partial match in Cypher? [duplicate]

Tags:

neo4j

cypher

For example, If a 'name' property's value is "iPhone 7" and my query term is "iPhone 8" I also want it to be matched.

match (n) WHERE n.name ~= $name ($name = 'iPhone 8')

If 'name' is 'iPhone 7', I want this returns true. Generally, if two strings largely matche, I want them to be matched:

"aabcde" matches "cdef": cde matches, but the 'contains' function won't work.

How to match at least these two examples in Cypher? Is this possible at all?

like image 582
user697911 Avatar asked Nov 15 '25 23:11

user697911


1 Answers

That specific example can use STARTS WITH. Also look at CONTAINS. Regular expressions will incur a performance hit.

From WHERE Clauses:

The STARTS WITH operator is used to perform case-sensitive matching on the start of strings.

MATCH (n)
WHERE n.name STARTS WITH 'Pet'
RETURN n.name, n.age

The name and age for the 'Peter' node are returned because his name starts with 'Pet'.

like image 106
pranspach Avatar answered Nov 17 '25 14:11

pranspach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!