cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Querying for prefix in a list

deepak
Node Clone

In the following example:

CREATE (:A)-[:AB{list:['k1:v1', 'k2:v2']}]->(:B)
CREATE (:A)-[:AB{list:['k2:v2']}]->(:B)

To find path with AB.list having an element k1:v1, I can use the following query:

WITH 'k1:v1' AS query
MATCH path = (:A)-[ab:AB]->(:B) WHERE query IN ab.list RETURN path

The query above uses an exact match in the list, but I only have a prefix k1: to query with. Is there a valid Cypher to achieve something like this?

WITH 'k1:' AS queryPrefix
MATCH path = (:A)-[ab:AB]->(:B) WHERE queryPrefix.* IN ab.list RETURN path
1 ACCEPTED SOLUTION

BairDev
Node Clone

Maybe you can try some trick with list.reduce()

reduce(totalAge = 0, n IN nodes(p) | totalAge + n.age)

in your case:

WHERE reduce(contains = 0, l IN ab.list | contains + CASE WHEN l CONTAINS 'k1:' THEN 1 ELSE 0 END) > 0

The syntax works, but I did not test it in a similar data set like yours.

View solution in original post

1 REPLY 1

BairDev
Node Clone

Maybe you can try some trick with list.reduce()

reduce(totalAge = 0, n IN nodes(p) | totalAge + n.age)

in your case:

WHERE reduce(contains = 0, l IN ab.list | contains + CASE WHEN l CONTAINS 'k1:' THEN 1 ELSE 0 END) > 0

The syntax works, but I did not test it in a similar data set like yours.