我正在尝试收集不同的节点路径长度,以及基于路径长度分配变量的目标。节点不在路径中=分离,路径长度为1 =半,路径长度> 1 =梯形。
我有以下密码,但是返回收集的列表时,即使每个部分都能正常工作,也不会返回任何内容。
match (a:Test) where not (a)-[]-() with a, COLLECT(DISTINCT a) as detached
match (a:Test)-[r]-() with a,detached,count(r) as rels where rels = 1
match path = (a)-[]->() with detached, COLLECT(DISTINCT NODES(path)) AS semis
match path = (a)-[:NEIGHBOURING_BUILDING*]-() where length(path) > 1 with detached, semis, COLLECT(DISTINCT NODES(path)) AS terraces
return detached, semis, terraces
我目前正在使用这个测试网络
create (:Test{id:1})
create (:Test{id:2})
create (:Test{id:3})-[:NEIGHBOUR]->(:Test{id:4})
create (:Test{id:5})-[:NEIGHBOUR]->(:Test{id:6})<-[:NEIGHBOUR]-(:Test{id:7})
create (:Test{id:8})-[:NEIGHBOUR]->(:Test{id:9})
create (:Test{id:10})-[:NEIGHBOUR]->(:Test{id:11})<-[:NEIGHBOUR]-(:Test{id:12})
如何将每种路径中的节点收集到列表中?
答案 0 :(得分:1)
您的查询有些奇怪:
match (a:Test) where not (a)-[]-() with a, COLLECT(DISTINCT a) as detached
match (a:Test)-[r]-() with a,detached,count(r) as rels where rels = 1
在第一行上,您正在搜索没有任何关系(a
)的节点not (a)-[]-()
,然后在第二行上,您需要此同一个节点的关系:{{1} }。
所以没有结果是正常的....