Reputation: 2522
I’ve been testing the following query
MATCH p=(me)-[*]-(rf)
WHERE me.name = "Filipa" AND rf.name="Anders"
RETURN p
Looking at the graph, in my understanding, the path should just return 2 direct paths (both with 2 hops) from Filipa to Anders , instead I get 2 extra paths both passing from Anders and looping back to Anders with 2 extra paths going in opposite directions after Anders node.
From my comment: @Christophe Willemsen
Since I haven’t included a relation direction, 2 paths should be present, instead I just get back one path. Both should be present:
(Filipa)->(Dilshad)->(Anders) //this path is present
(Anders)->(Dilshad)->(Filipa) //This path is NOT present, why??
Furthermore in the "results" the following paths are included:
(Filipa)->(Dilshad)->(Anders)->(Becky)->(Emil)->(Cesar)->(Anderes) //These 2 paths pass 2 times at Anders node. Why??
(Filipa)->(Dilshad)->(Anders)->(Cesar)->(Emil)->(Becky)->(Anderes)
The latter 2 paths are both passing twice to Anders’s node, why? This Doesn’t make any sense, if this is the logic we could have infinite paths?
Upvotes: 0
Views: 321
Reputation: 20185
There are two points with your query :
You match an entire pattern, with * length of relationships, meaning that if he find a path with 2 hops and one with 3 hops you'll get the both in return.
You do not specify a direction of your relationship, so he will automatically find at least two paths, one in one way and one in another way.
You can specify relationship directions with an arrow :
MATCH p=(me)-[*]->(rf)
You can limit the return of the amount of paths to 1 :
MATCH p=(me)-[*]->(rf)
WHERE me.name = "Filipa" AND rf.name="Anders"
RETURN p
LIMIT 1
You can get the shortest path from me to Anders with the shortestPath
clause :
MATCH p=shortestPath((me)-[*]->(rf))
which is automatically limited to one result
Upvotes: 2