Cypher:找到满足步骤i和i + 1之间条件的路径

时间:2014-10-08 16:35:32

标签: neo4j cypher

我正在尝试编写一个cypher查询,该查询返回一个路径,其条件是每个步骤必须具有一个值小于或等于上一步的timestamp属性。以下是我到目前为止的情况。

Match path=(a:NODE)-[:PARENT*]->(b:NODE)
WHERE a.name='SOME_VALUE' and b.name='SOME_OTHER_VALUE'
WITH path, relationships(path) as steps
WHERE ALL ( i in Range(0, length(steps) - 1) WHERE steps[i].timestamp <= steps[i+1].timestamp)
RETURN path

我认为我所拥有的是关闭,但是neo4j网络控制台告诉我我有语法错误。

Invalid input '.': expected whitespace, '[', "=~", IN, IS, '^', '*', '/', '%', '+', '-', '<', '>', "<=", ">=", '=', "<>", "!=", AND, XOR, OR or ')' (line 4, column 60)
"WHERE ALL ( i in Range(0, length(steps) - 1) WHERE steps[i].timestamp <= steps[i+1].timestamp)"
                                                            ^

我已经在另一个stackoverflow question上看到了以这种方式访问​​的关系集合的属性,所以我不知道我做错了什么。

1 个答案:

答案 0 :(得分:1)

你的陈述非常接近。您需要将steps[i]括在括号中:

Match path=(a:NODE)-[:PARENT*]->(b:NODE)
WHERE a.name='SOME_VALUE' and b.name='SOME_OTHER_VALUE'
WITH path, relationships(path) as steps
WHERE ALL ( i in Range(0, length(steps) - 1) WHERE (steps[i]).timestamp <=     (steps[i+1]).timestamp)
RETURN path