neo4j - 如果 2 个节点之间有一个节点,则 Neo4J 深度
问题描述
我有以下查询:
MATCH
(exp:Expert {name: "Somebody"})-[:PUBLISHED_BY]-(pub1:Publication)-[:PUBLISHED_BY]-(coexp:Expert),
(coexp:Expert)-[:PUBLISHED_BY]-(pub2:Publication)-[:PUBLISHED_BY]-(cocoexp:Expert)
RETURN exp,pub1,pub2,coexp,cocoexp
LIMIT 300
我想返回的是以下内容:
(expert)--(publication)--(coexpert)
(expert)--(publication)--(coexpert)--(publication)--(cocoexpert)
但它也返回:
(expert)--(publication)--(coexpert)--(publication)--(cocoexpert)--(publication)--(cococoexpert)
...
在第二部分中,我尝试做:
(coexp:Expert)-[:PUBLISHED_BY]-(pub2:Publication)-[:PUBLISHED_BY*0..1]-(cocoexp:Expert)
但没有成功。谢谢你的帮助。
解决方案
您的查询存在基数问题。如果您想选择性地匹配第二部分,您可以将其分开并添加一个可选的匹配子句。以下查询应按预期工作:
MATCH (exp:Expert {name: "Somebody"})-[:PUBLISHED_BY]-(pub1:Publication)-[:PUBLISHED_BY]-(coexp:Expert)
OPTIONAL MATCH (coexp)-[:PUBLISHED_BY]-(pub2:Publication)-[:PUBLISHED_BY]-(cocoexp:Expert)
Where exp<>coexp And exp<>cocoexp And coexp<>cocoexp
RETURN exp,pub1,pub2,coexp,cocoexp
LIMIT 300
推荐阅读
- c++ - c ++ struct - 使用计数器修改内部for循环
- laravel - 如何避免 laravel 验证中的重复值?
- java - Mirth Connect 使用 mdth 库获取遭遇详情
- docker - 如何通过谷歌函数在谷歌容器注册表中运行 docker 容器?
- javascript - Web 应用程序输入类型文件在 WebView 中不起作用
- python-3.x - 使用 pandas 和 matplotlib 绘制带有条形图的子组标签
- javascript - JQGrid - 在没有本地数据的情况下管理分页和列过滤(loadonce = false)
- javascript - 在 Laravel 中实现可嵌入的自定义徽章
- javascript - 如何在本机反应中记录每次更新的动画值?
- django - 如何在 django 布尔字段上应用条件?