Neo4j: Cypher计算从allShortestPaths找到的总路径?

时间:2020-11-24 19:10:55

Is there a way to get the count on total number of paths found from allShortestPaths within queries of type

是否有一种方法可以计算在类型查询中从allshortestpath中找到的路径总数?

Match (n:Person{personid:123}), (m:Person{personid:456}), p =allShortestPaths(n-[r*1..6]-m) with reduce(weight = 0, rel in rels(p) | weight + rel.weight) AS weight, n, m,p return n, m, p,weight order by weight limit 25

1 个解决方案

#1


3  

Here is one way (by collecting the paths, getting the length of the collection, and then unwinding the collection back into path rows).

这里有一种方法(通过收集路径,获取集合的长度,然后将集合回退到路径行)。

MATCH (n:Person { personid:123 }),(m:Person { personid:456 }), p =allShortestPaths(n-[r*1..6]-m)
WITH n, m, COLLECT(p) AS paths
WITH n, m, paths, LENGTH(paths) AS totalPaths
UNWIND paths AS p
RETURN n, m, totalPaths, p, reduce(weight = 0, rel IN rels(p)| weight + rel.weight) AS weight
ORDER BY weight
LIMIT 25

#1


3  

Here is one way (by collecting the paths, getting the length of the collection, and then unwinding the collection back into path rows).

这里有一种方法(通过收集路径,获取集合的长度,然后将集合回退到路径行)。

MATCH (n:Person { personid:123 }),(m:Person { personid:456 }), p =allShortestPaths(n-[r*1..6]-m)
WITH n, m, COLLECT(p) AS paths
WITH n, m, paths, LENGTH(paths) AS totalPaths
UNWIND paths AS p
RETURN n, m, totalPaths, p, reduce(weight = 0, rel IN rels(p)| weight + rel.weight) AS weight
ORDER BY weight
LIMIT 25