本文介绍了Neo4j可变深度不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为两种情况建立密码查询:

I am trying to build a cypher query for two scenarios :

  1. 深度大于2的测试
  2. 深度大于2的特定测试

在图像中,您可以看到测试1、2、3在深度超过2时有些相关.我运行的密码是:

As in Image you can see tests 1, 2, 3 are somewhat related through depth more than 2. The cypher which i ran was :

MATCH p=()<-[r:TEST_FOR*..10]-() RETURN p LIMIT 50

现在,当我将密码更改为以下密码时,我将没有记录/结果或节点.

Now when i Change my cypher to below then i get no records/results or nodes.

1) MATCH p=()<-[r:TEST_FOR*2..5]-() RETURN p LIMIT 50
2) MATCH p=()<-[r:TEST_FOR*2]-() RETURN p LIMIT 50
3) MATCH p=(d:Disease)<-[r:TEST_FOR*]-(t:Tests) WHERE t.testname = 'Alkaline Phosphatase (ALP)'  RETURN p
4) MATCH p=()<-[r:TEST_FOR*..10]-(t:Tests {testname:'Alkaline Phosphatase (ALP)'}) RETURN p LIMIT 50

当我运行上面的查询3和4时,我得到相同的结果,即1种有5种疾病的测试,但是对于该特定测试没有进一步扩展.

When I run Query 3 and 4 above, I get same results, i.e 1 test with 5 diseases, but it does not extend out further for that specific test.

但是,如果您看到图像,则说明该测试已连接到其他两个测试!我的结构如下:

But if you see the image the test is connected to two other tests ! My structure is as follows :

  1. 测试(测试名称)
  2. 疾病(疾病名称,确实)
  3. Linknode(parentdieaseid,测试名称)

我已使用以下查询创建关系"TEST_FOR"

I had used below query to create Relationship "TEST_FOR"

match(d:Disease), (l:Linknode) where d.did = l.parentdiseaseid
with d, l.testname as name
match(t:Test {testname:name}) create (d)<-[:TEST_FOR]-(t);

推荐答案

方向是这里的问题.上面的4个查询中的每个查询都使用 directed 可变长度匹配模式,这意味着遍历的每个关系都必须使用指示的方向(传入).但是,一旦您点击:Tests节点,那将不起作用,因为它们仅与:Disease节点具有外向关系.

Direction is the problem here. Each of your 4 queries above uses a directed variable-length matching pattern, meaning that every relationship traversed must use the direction indicated (incoming). However, that won't work once you hit :Tests nodes, since they only have outgoing relationships to :Disease nodes.

简单的解决方法是忽略方向,因此匹配的模式将遍历:TEST_FOR关系,而与方向无关.例如:

The easy fix is to omit the direction, so the matching pattern will traverse :TEST_FOR relationships regardless of direction. For example:

MATCH p=()-[r:TEST_FOR*2..5]-() RETURN p LIMIT 50

请注意您原始查询的原因

Note that the reason your original query

MATCH p=()<-[r:TEST_FOR*..10]-() RETURN p LIMIT 50

返回完整图是因为它从未遍历每个:Disease节点的单个跃点(因为它永远无法遍历:Tests节点的传入:TEST_FOR关系),而是从每个:Disease节点,因此很自然地也会碰到每个:Tests节点.您将获得与此相同的图形:

was returning the full graph is because it was never traversing deeper than a single hop from each :Disease node (since it would never be able to traverse an incoming :TEST_FOR relationship from a :Tests node), but it was starting from every :Disease node, so naturally that hit every single :Tests node as well. You would have gotten the same graph with this:

MATCH p=()<-[r:TEST_FOR]-() RETURN p LIMIT 50

这篇关于Neo4j可变深度不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 10:17