在路径上的所有节点上执行MATCH [英] Performing a MATCH on all nodes on a path
问题描述
是否可以在MATCH模式> ALL
函数(使用v1.8)?
Is it somehow possible to use a MATCH
pattern inside the ALL
function (using v1.8)?
我要执行的操作如下:我正在MATCH
设置路径p = (a)-->(b)-->(c)-->(d)
.但是,沿该路径的所有节点都必须具有来自某个节点的附加传入关系r
.让我试着用ASCII明确这一点:
What I am trying to do is the following: I am MATCH
ing a path p = (a)-->(b)-->(c)-->(d)
. However, all nodes along this path must have an additional incoming relationship r
from some node. Let me try to make this clear in ASCII:
(a)-->(b)-->(c)-->(d)
^ ^ ^
|r |r |r
( ) ( ) ( )
我可以以某种方式使用ALL
函数还是必须添加其他如下的MATCH
模式:
Can I somehow use the ALL
function for that or do I have to add additional MATCH
patterns like this:
START ...
MATCH (a)-->(b)-->(c)-->(d)..., ()-[:r]->(b), ()-[:r]->(c), ...
RETURN ...
更新:
Update:
以下是 Neo4j控制台中的示例:
START n=node(0)
CREATE (a), (b), (c), (d), (e),
n-[:rel1]->a, n-[:rel1]->b, n-[:rel1]->d, n-[:rel1]->e,
a-[:rel2]->b-[:rel3]->d, a-[:rel2]->c-[:rel3]->e
START n=node(0)
MATCH n -[:rel1]-> x -[:rel2]-> y -[:rel3]-> z, ()-[:rel1]->y, ()-[:rel1]->z
RETURN z
推荐答案
您可以使用WHERE ALL来做到这一点,就像这样:
You can do this using WHERE ALL, like this:
START n=node(0)
MATCH path = n -[:rel1]-> x -[:rel2]-> y -[:rel3]-> z
WHERE ALL(n in tail(nodes(path)) WHERE ()-[:rel1]->n)
RETURN z
tail(nodes(path))返回路径中除第一个节点外的所有节点.在您的示例中,起始节点未与rel1关系连接,因此未返回任何内容.如果您想按照文字说明进行操作,只需将尾部放下即可.
tail(nodes(path)) returns all nodes in the path except the first one. In your example, the start node was not connected with a rel1 relationship, so nothing was returned. If you want to do it like your text explains it, just drop the tail part.
这是您要找的吗?
这篇关于在路径上的所有节点上执行MATCH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!