Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-18-2022 09:13 PM
I have one requirement where I need all paths between two nodes. So first I tried to fetch all paths using AllShortestPath() and then need to order them using some specific criteria. My issue is that I am using the below query and getting one path
MATCH (source:A{id:11}), (target:A{id:13}) WITH source,target MATCH path = allShortestPaths((source)-[*]-(target)) RETURN path
When I have made the below change MATCH path = allShortestPaths((source)-[:RelA|RelB*]-(target))
I am getting different path. But the first one is generic one So I should get all paths.
I am not able to understand why the function is behaving differently
07-19-2022 04:25 AM
I don't know your data to validate my hypothesis, but it would seem that your overall shortestPaths (no relationship type constraint) is shorter that the paths between source and target that must traverse through relationships of type 'RelA' or 'RelB'. This would explain your results.
For example, create test data with two paths. The shortest path has one hop, while the second path has three hops.
create(n:Node{id:0})-[:REL]->(m:Node{id:1})
merge(n)-[:RelA]->()-[:RelB]->()-[:RelA]->(m)
As shown, the shortest path from id=0 to id=1 is through the single 'REL' relationship. If I restrict my path to having to traverse only 'RelA' or 'RelB' relationships, then the overall shortest path is not a candidate any longer and the shortest path is now the path through nodes 72 and 73.
All the sessions of the conference are now available online