I want to return all nodes/relationships until I find the first node that has a certain relationship in an arbitrary number of iterations.
Example
Given:
X(1)-[foo]->X(2)-[foo]->X(3)-[bar]->X(4)-[foo]->X(5)
I want this returned:
X(1)-[foo]->X(2)-[foo]->X(3)-[bar]->X(4)
This does NOT work:
MATCH (f:X), r=(f)-[:foo|bar*1..]->(t:X)
WHERE id(f) = 1 AND NOT ()-[:bar]->(f)
WITH f, relationships(r) AS rs, nodes(r) AS ns
RETURN f, rs, ns
It returns the entire graph:
X(1)-[foo]->X(2)-[foo]->X(3)-[bar]->X(4)-[foo]->X(5)
Is this because of the 2 WHERE conditions being temporally at odds?
How do I change it to work?
In addition, I'd like to filter on the ID of the last traversed relationship is in the terminating condition.
like (yes, this is invalid, silly syntax):
MATCH (f:X), r=(f)-[:foo|bar*1..]->(t:X)
WHERE id(f) = 1 AND NOT (f-1)-[:bar]->(f)
WITH f, relationships(r) AS rs, nodes(r) AS ns
RETURN f, rs, ns
Is this all too complex for Cypher??