本文介绍了如何获取neo4j路径中的最后一个节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此密码查询中,将返回与STATUS ="on"属性相互关联的节点之间的最长路径/路径,但我也想获得该路径的最后一个节点.
In this cypher query,the longest path/paths between nodes which have relationship with STATUS="on" property with each other,will be returned,but I want to get also the last node of the path/paths.
查询:
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
如何将其添加到查询中?谢谢.
how should I add it to the query?thanks.
推荐答案
这将给出两个数组.第一个数组是每个路径中的最后一项,第二个数组是每个路径:
This would give two arrays. The first array is the last item in each path, the second is each path:
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
WITH FILTER(path IN paths WHERE length(path)= maxLength) AS longestPaths
RETURN EXTRACT(path IN longestPaths | LAST(path)) as last, longestPaths
这篇关于如何获取neo4j路径中的最后一个节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!