我使用 cypher 来计算两个节点之间的路径数量。我有这样的疑问:
MATCH p=(a)-[*1..2]-(b)
where ID(a) = "node1"
and ID(b) = "node2"
return COUNT(p)
但是,我的许多节点都有多个链接到具有不同关系类型的同一节点。我只想计算不同的路径,无论关系类型如何。
例如返回的路径可能如下:
(node1)-[rel_type_a]-(node3)-[rel_type_b]-(node2)
(node1)-[rel_type_c]-(node3)-[rel_type_d]-(node2)
(node1)-[rel_type_e]-(node3)-[rel_type_f]-(node2)
上面的查询将其计为 3 条路径,但我只想将其计为单个路径,因为所有节点都相同,我对关系类型不感兴趣。
提前致谢!
我发现以下查询有效:
MATCH p=(a)-[*1..2]-(b)
where ID(a) = "node1"
and ID(b) = "node2"
return count(distinct(nodes(p)))
如果有更好的方法来做到这一点,我洗耳恭听!