繁体   English   中英

Neo4J深度(如果两个节点之间有一个节点)

[英]Neo4J Depth if there a node between 2 nodes

我有以下查询:

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子句。 以下查询应该可以正常工作:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM