繁体   English   中英

Cypher 查询:按关系属性查找路径

[英]Cypher query: find path by relationship properties

我的问题与这个主题非常接近: Cypher 查询:查找由关系属性过滤的两个节点之间的所有路径,但我想要做的是找到沿路径具有递增关系属性值的路径。 因此,在之前的主题中,示例解决方案路径(从 A 到 D)将是:

A->DA->B->D

我使用了上一个主题的解决方案

START a=node(1), d=node(4) 
MATCH p=a-[r:ACTIVATES*..]->d 
WITH head(relationships(p)) as r1,p
WHERE all(r2 in relationships(p) 
      where r2.temperature > r1.temperature) 
return p;

它适用于这个例子。 问题是当有超过 2 个关系的路径时,例如:

    activates:50      activates:70      activates:60
(A)-------------->(B)-------------->(C)-------------->(D)

不幸的是,这条路径也匹配。

有没有办法用密码编写这个查询,或者我必须改用gremlin?

感谢您的任何建议。

更新:我需要的是一些结构(用伪编程语言):

WITH head(relationships(p)) as r1,p
FOREACH(r2 in tail(relationships(p)):
    r1.temperature < r2.temperature, r1 = r2)

但如果可能的话,在密码中。

这个在我的例子中有效

START a=node(1), d=node(4) 
MATCH p=a-[r:ACTIVATES*..]-d 
WITH head(relationships(p))as r1,last(relationships(p))as r2,p
WHERE all(r3 in relationships(p) 
      where r2.temperature > r1.temperature AND NOT r3.temperature < r1.temperature) 
return p;

更新:有没有办法用节点属性来做到这一点?

暂无
暂无

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

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