how to find all the longest paths with cypher query?

后端 未结 1 1729
清酒与你
清酒与你 2020-12-19 08:07

I want to write a cypher query which finds all the longest paths among nodes which have relationship with STATUS=\"on\" property with each other,this is what I hav

相关标签:
1条回答
  • 2020-12-19 08:33

    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
    
    0 讨论(0)
提交回复
热议问题