Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4J Cypher通过多种关系类型匹配-奇怪的行为_Neo4j_Cypher - Fatal编程技术网

Neo4J Cypher通过多种关系类型匹配-奇怪的行为

Neo4J Cypher通过多种关系类型匹配-奇怪的行为,neo4j,cypher,Neo4j,Cypher,我的图表是这样的 start n=node(543) match n-[:firstChapter|nextChapter*]->m return m; 中-[:第一章]->第1章-[:下一章]->第2章至第N章 只有一个节点通过:firstChapter连接,随后可能会有几个节点通过:nextChapter连接 我尝试匹配通过relationship:firstChapter连接到medium或通过nextChapter连接到另一章的所有节点 我尝试的查询如下所示 start n=no

我的图表是这样的

start n=node(543) match n-[:firstChapter|nextChapter*]->m return m;
中-[:第一章]->第1章-[:下一章]->第2章至第N章

只有一个节点通过:firstChapter连接,随后可能会有几个节点通过:nextChapter连接

我尝试匹配通过relationship:firstChapter连接到medium或通过nextChapter连接到另一章的所有节点

我尝试的查询如下所示

start n=node(543) match n-[:firstChapter|nextChapter*]->m return m;
节点(543)是节点介质。 令人惊讶的是,此查询返回路径中的所有节点,即使这些节点未连接到n(=中间节点) 如果在nextChapter之后省略*符号,则只返回具有:firstChapter关系的第一个节点(第1章),这似乎是正确的

start n=node(543) match n-[:firstChapter|nextChapter*]->m return m;
为什么上面的查询返回未连接到n的节点?据我所知,*符号通常返回的节点数量不限,对吗

匹配路径中通过:firstChapter或:nextChapter连接到起始节点的所有节点(仅一次)的最佳方法是什么?在本例中,所有章节

上面的查询就是为了这个目的,但我认为输出不正确

编辑: 添加了一个图表来澄清。 正如你所看到的,第一章只能通过以下途径达到:第一章, 因此,仍然不清楚为什么上面的查询会返回所有章节节点
试着做
匹配p=n-[:firstChapter | nextChapter*]->m
看看p是什么。希望这能提供一些关于它们如何连接的见解

您最终可能会寻找的是:

start n=node(543) 
match n-[:firstChapter|nextChapter*]->m 
return collect(distinct m);
以获取n后面的不同章节节点的集合

更新 这是另一个——实际上并没有测试它,但它可能会让你更接近你想要的:

start n=node(543)
match n-[:firstChapter]->f-[:nextChapter*]-m
return f + collect(distinct m);

使用*运算符,查询将查找以下两种关系类型的所有关系::firstChapter和:nextChapter(不仅仅是:nextChapter)。节点(543)的章节数据可能包含与不在543链中的章节节点的某些关系,查询将返回这些关系

考虑使用type:nextChapter添加一个额外的关系,以将开始节点连接到第一章,并检查章节上存在的关系

然后运行:

start n=node(543) 
match n-[:nextChapter*]->m 
return m;
看看你是否还能得到额外的结果。如果是这样,您可以运行以下命令,每次递增n,直到找到具有额外关系的节点(尽管我相信还有其他方法!)


这并不能回答这个问题。若要评论或要求作者澄清,请在其帖子下方留下评论。他们问“为什么上面的查询返回未连接到n的节点?”我试图回答这部分问题。我已更新了答案以提供更多信息。抱歉,我很匆忙,没有提供太多解释。您是否尝试返回路径,以查看其连接的位置?是的,我尝试了,并且似乎是正确的。也许我只是误解了这个问题的意思。我认为它与第一章的关系相匹配,并且连接到起始节点(543)的nextChapter的路径长度不限。它的作用似乎是:匹配一条无限长的路径,路径上要么有第一章的关系,要么有第二章的关系。所以*符号似乎影响了整个表情,而不仅仅是下一章。我说得对吗?