neo4j - 在 neo4j 中使用 cypher 收集不同路径长度的节点
问题描述
我正在尝试收集节点的不同路径长度以及基于路径长度分配变量的目标。不在路径中的节点 = 分离,路径长度 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]-()
。
所以没有结果是正常的......
推荐阅读
- azure - Azure 服务总线队列或主题中的分区数量是否有任何限制?
- html - GoJS:如何通过在图中搜索节点来获取节点数据?
- mysql - 在mysql中找到与另一个线串相交的所有线串
- flutter - Flutter 会话 API 登录
- angular - Angular JIT 编译失败:未加载“@angular/compiler”
- python - 当测试集中有新数据时使用带有管道的序数编码
- paypal - 在 Magento 2.4.0 中,使用 paypal 付款方式下达的访客订单未在 Google 分析转换中进行跟踪?
- android - 如何获取自定义的sensors.imx8.so供Android使用?
- ionic-framework - 如何以编程方式在安装后检索应用程序占用的内存
- python-3.x - 没有聚合的python上的Groupby