This question is a direct extension of a question I asked previously.
Say I have a graph database that looks like this:
Just like the previous question
This query will filter out all sub-paths from the results:
MATCH p=(a:person)-[:RELATED_TO*]->(b:person)
WHERE
NOT ()-[:RELATED_TO]->(a) AND
NOT (b)-[:RELATED_TO]->() AND
2 < REDUCE(s = 0, x IN NODES(p) | CASE WHEN x. SomeProperty = 'Yes' THEN s + 1 ELSE s END)
RETURN p;
Explanation:
NOT ()-[:RELATED_TO]->(a)
is true if the a
node is not the at the end of a RELATED_TO
relationship.NOT (b)-[:RELATED_TO]->()
is true if the b
node is not at the start of a RELATED_TO
relationship.Therefore, a matching path cannot be a sub-path.