I am doing the coursera coursework for NEO4J at an institution.
I note that the examples on paths and lengths and shorest path all show on my machine different results to that in the course notes /lectures.
I am using 3.0.6. Are there bugs? I note that it seems to disregard direction of edge. Could it be some setting that I need to set?
Thanks in advance
LOAD
CSV WITH HEADERS FROM "file:///C:/coursera/data/test.csv" AS line
MERGE (n:MyNode {Name:line.Source})
MERGE (m:MyNode {Name:line.Target})
MERGE (n) -[:TO {dist:line.distance}]-> (m)
match p=(a)-[:TO*]-(c)
where a.Name='H' and c.Name='P'
return p limit 1
The query you're using:
match p=(a)-[:TO*]-(c)
where a.Name='H' and c.Name='P'
return p limit 1
The match itself finds one possible path between the two given nodes using that pattern. It makes no guarantees about distance or ordering (I ran this on mine and it returned a fairly convoluted path, far from from shortest distance). If the course notes said that this is a shortest path query, then it's wrong.
In neo4j, the only way to enforce and guarantee shortest path is with the shortestPath() function, or allShortestPaths(). For example:
match p= shortestPath((a)-[:TO*]-(c))
where a.Name='H' and c.Name='P'
return p limit 1
EDIT
As you noted, the query you're using is undirected, so it will traverse any relationship it finds regardless of direction to find a path. There is a significant difference between matching on an undirected relationship pattern vs a directed relationship pattern. You can try running the query with a directed relationship and see the difference.
match p= shortestPath((a)-[:TO*]->(c))
where a.Name='H' and c.Name='P'
return p limit 1