how to find all the longest paths with cypher query?

ε祈祈猫儿з 提交于 2019-11-29 10:38:51

Try moving up your relationship property criterion to the first path match, or you'll be calculating the max length on paths that are not filtered with that criterion. Then carry the paths and the max length into the second leg of the query so you don't have to match all the paths again. You can collect the paths to carry them in the WITH clause, and then filter on path length when you return. Try something like

START n=node(*)
MATCH p=n-[rels:INCLUDE*]->m 
WHERE ALL (rel IN rels 
  WHERE rel.status='on') 
WITH COLLECT(p) AS paths, MAX(length(p)) AS maxLength 
RETURN FILTER(path IN paths 
  WHERE length(path)= maxLength) AS longestPaths
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!