简体   繁体   中英

Cypher allShortestPaths just return one path?

Background statement:

  • I have a graph like bellow: 在此处输入图片说明

  • I want to find all the path between Node A and Node F (something like how many ways I can reach F from A), then my Cypher like this bellow:

 MATCH (start:kg:test), (end:kg:test), p = allShortestPaths((start)-[*..8]-(end)) where start.value = 'A' and end.value = 'F' RETURN start, end, p 
  • As I expected, this query will return the whole graph, but it just returns A->F (return the same thing with using the shortestPath function), like bellow: 在此处输入图片说明

Problems

  • Why that query won't return all the different paths in the graph?
  • Do I misuse the allShortestPaths function?
  • How can I get all the path from Node A to Node F?

thanks

shortestPath() returns the single shortest path between the nodes (and if there are multiple of the same size it just returns the first that it finds).

If there are multiple paths that could have been returned by shortestPath() (they will all have the same size), then allShortesPaths() will return them.

If you just want to find all possible paths between two nodes (the length of the path doesn't matter, and you don't care about shortest paths at all), then you don't need to use either of these functions.

MATCH p=(start:kg:test)-[*..8]-(end:kg:test)
    where start.value = 'A' and end.value = 'F'
    RETURN start, end, p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM