简体   繁体   English

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

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

I have the following query: 我有以下查询:

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

What I'd like to return is the following: 我想返回的是以下内容:

(expert)--(publication)--(coexpert)
(expert)--(publication)--(coexpert)--(publication)--(cocoexpert)

But it returns also: 但它也返回:

(expert)--(publication)--(coexpert)--(publication)--(cocoexpert)--(publication)--(cococoexpert)
...

In the second part I tried to do: 在第二部分中,我尝试执行以下操作:

(coexp:Expert)-[:PUBLISHED_BY]-(pub2:Publication)-[:PUBLISHED_BY*0..1]-(cocoexp:Expert)

But no success. 但是没有成功。 Thanks for your help. 谢谢你的帮助。

Your query has cardinality issue. 您的查询有基数问题。 If you want to match the second part optionally you can separate it and add an optional match clause to it. 如果要匹配第二部分,则可以将其分开,并在其中添加可选的match子句。 Following query should work as expected: 以下查询应该可以正常工作:

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