Lucas Azevedo
Lucas Azevedo

Reputation: 2370

Complex path query with cypher

I have a sentence graph in neo4j and I would like to know how to do a complex query that would start and end with a node with the :WORD label and return a path between them.

The point is that I want it to have varying length and only return paths that goes through nodes with certain properties. I would like something like:

MATCH p=((p1:Word)-[r*0..4](***)-(p2:Word))
WHERE v:Variable {property = value} 
RETURN p1,p2,p AS Path, length(p) AS PathSize 
ORDER BY PathSize

***: Here I would like to name the nodes of the middle of the path as v and filter only the paths where the v's have a certain property. Does anyone knows how to do it?

Thank you!

Upvotes: 0

Views: 235

Answers (1)

cybersam
cybersam

Reputation: 66957

[EDITED]

This is probably what you are looking for:

MATCH p=(p1:Word)-[*0..4]-(p2:Word)
WHERE ALL(v IN NODES(p) WHERE v.property = value)
RETURN p1, p2, p AS Path, LENGTH(p) AS PathSize 
ORDER BY PathSize;

Upvotes: 1

Related Questions