[英]Find all Nodes and Relations up to a defined path length within Neo4j using Cypher
[英]collecting nodes of varying path length using cypher in neo4j
我正在尝试收集不同的节点路径长度,以及基于路径长度分配变量的目标。 节点不在路径中=分离,路径长度为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})
如何将每种类型的路径中的节点收集到列表中?
您的查询有些奇怪:
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)-[]-()
),然后在第二行上,您想要该同一个节点的关系: (a:Test)-[r]-()
。
所以没有结果是正常的....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.