我有一个cypher查询,它当前返回具有可变长度路径的给定节点的所有关系:
MATCH (n)
WHERE n.name = ({name})
OPTIONAL MATCH path=n-[*..2]-(c)
WHERE n <> c
WITH rels(path) AS rels
UNWIND rels AS rel
WITH DISTINCT rel
RETURN startnode(rel).name as source, endnode(rel).name as target, rel.average_alignment
我希望将路径长度添加为返回的一部分:
MATCH (n)
WHERE n.name = ({name})
OPTIONAL MATCH path=n-[*..2]-(c)
WHERE n <> c
WITH rels(path) AS rels
UNWIND rels AS rel
WITH DISTINCT rel
RETURN startnode(rel).name as source, endnode(rel).name as target, rel.average_alignment, length(path)
如何包含路径长度以及所有关系?
答案 0 :(得分:2)
WITH
子句删除所有先前定义的标识符(如path
),除非它们在子句中指定。您的第一个WITH
子句未指定path
(或仅指定路径的长度),因此它已被删除。
这样的事情对你有用:
MATCH (n) WHERE n.name = {name}
OPTIONAL MATCH path = (n)-[*..2]-(c)
WHERE n <> c
WITH LENGTH(path) AS lth, RELS(path) AS rels
UNWIND rels AS rel
WITH DISTINCT lth, rel
RETURN STARTNODE(rel).name as source, ENDNODE(rel).name as target, rel.average_alignment, lth;