![](/img/trans.png)
[英]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.