I want to find ALL the paths starting and ending from/to a specific node. I would like that each node in a path appears only once.
For example, in a graph like this:
(a)-[:REL]->(b)-[:REL]->(c)-[:REL]->(a)
(a)-[:REL]->(e)-[:REL]->(f)-[:REL]->(a)
(e)-[:REL]->(b)
grafically:
e → b
↙ ↖ ↗ ↘
f → a ← c
Cypher code:
CREATE (a { name:'A' })-[:REL]->(b {name:'B'})-[:REL]->(c { name:'C' })
-[:REL]->(a)-[:REL]->(e {name:'E'})-[:REL]->(f {name:'F'})-[:REL]->(a),
(e)-[:REL]->(b)
I would like that the research of chains starting from (a) returns
(a)->(b)->(c)->(a)
(a)->(e)->(f)->(a)
(a)->(e)->(b)->(c)->(a)
while starting from (f) returns only
(f)->(a)->(e)->(f)
and NOT
(f)->(a)->(b)->(c)->(a)->(e)->(f)
because it passes twice through the node (a).
I tryied:
MATCH p=(a {name:'F'})-[:REL*1..]->(a)
WHERE SINGLE(e1 IN TAIL(NODES(p)) WHERE SINGLE(e2 IN TAIL(NODES(p)) WHERE e1=e2))
RETURN p
but I've got no result. The best I've been able to reach is to have no repetition of just the start node with this query:
MATCH p=(a {name:'F'})-[:REL*1..]->(a)
WHERE SINGLE(e IN TAIL(NODES(p)) WHERE e=a)
RETURN p
but obviously it's not what I want because it returns also
(f)->(a)->(b)->(c)->(a)->(e)->(f)
that is a path involving the node (a) twice.
Can someone suggest me a solution?
Thank you in advance.
P.S. The version of Neo4j that I use is 2.0