我的查询返回路径:
match path = ...
return path
但缺少节点和关系标签。我该如何添加它们?
return path, labels(path)
给出错误
答案 0 :(得分:0)
您可以在整个路径中使用命名节点。然后对每个命名节点(labels(a) + labels(b)
)的标签求和。之后,您可以使用UNWIND
和collect distinct
删除重复项。此外,您可以使用relationships()函数来获取关系类型。
match path = (a)-->(b)
with path, labels(a) + labels(b) as labels, relationships(path) as relationships
unwind(labels) as label
unwind(relationships) as relationship
return path, collect(distinct label) as labels, collect(distinct type(relationship)) as relationships
答案 1 :(得分:0)
我设法实现的最好的事情是
match path = ...
return path, extract (x in rels(path) | type(x)) as types, extract (n in nodes(path) | labels(n)) as labels
它允许人们重建后端的整个路径结构。虽然仍然包含很多重复