当条件为真时,使neo4j / cypher查询停止

时间:2012-09-22 04:25:20

标签: neo4j cypher

我有一个图表,其中每个节点代表一个java类,每个节点都有一个名为namespace的属性。我想匹配起始节点和最终节点共享命名空间但所有中间人不共享该命名空间的模式。对于我有3类(A类 - > B类 - > C类)的情况:

START inside1 = node(*) 
match inside1 -[:USES]-> outside1 -[:USES] -> inside2  
where inside1.namespace <> outside1.namespace 
  and inside2.namespace = inside1.namespace  
return inside1.name, outside1.name, inside2.name

这似乎工作正常。当我试图扩展它时,我尝试了:

START inside1 = node(*) 
match inside1 -[:USES]-> outside1 -[:USES*] -> inside2  
where inside1.namespace <> outside1.namespace 
  and outside1.namespace <> inside1.namespace 
  and inside2.namespace = inside1.namespace  
return inside1.name, outside1.name, inside2.name

问题是我不想要任何中间节点与inside1共享相同名称空间的路径。所以我的问题是,无论如何,我可以告诉它“当你点击名称空间等于inside1.namespace的节点时停止吗?”

感谢。

1 个答案:

答案 0 :(得分:3)

不确定它是否最简洁,但我认为这样做你想要的?首先,它会查询您的查询的一般情况,然后将其限制为只有match的最短with

 START inside1 = node(*) 
 MATCH inside1-[:USES*]->outside1-[:USES]->inside2 
 WHERE inside1.ns <> outside1.ns 
   AND inside2.ns = inside1.ns 
  WITH inside1, inside2, outside1 
 MATCH inside1-[:USES]->outside2 
 WHERE inside1.ns <> outside2.ns 
RETURN inside1, outside1, inside2

http://console.neo4j.org/r/m8iqo5