Neo4j Cypher:如何从路径中解包节点以允许进一步匹配? [英] Neo4j Cypher: How do you unpack nodes from a path to allow for further matching?

查看:102
本文介绍了Neo4j Cypher:如何从路径中解包节点以允许进一步匹配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是问题之后的问题这里

我有一个具有循环链表的图. (请参见此处的示例)链接列表中的每个节点都指向一个用户.查询列表时,我必须使用路径语句,因为列表是循环的,并且我不想从u:USER节点开始检索节点.为了获得感兴趣的节点,我的查询如下所示:

I have a graph that has a circular linked list. (see here for an example) Each node in the linked list points to a User. When querying the list I have to use a path statement as the list is circular and I do not want to retrieve nodes beginning from the u:USER node. In order to get the nodes of interest my query looks like this:

MATCH path=(nl:NODELINK { linkId:'cc' })-[:LINK*]->(u:USER)
RETURN nodes(path)

检索到路径后,我想对该路径中的节点(NODELINK的)进行进一步的匹配,如下所示:

Once I have retrieved the path I would like to do further matching against the nodes in that path (the NODELINK's), somthing like the following:

MATCH path=(nl:NODELINK { linkId:'cc' })-[:LINK*]->(u:USER)
WITH nodes(path) AS nodeLinks
MATCH nodeLinks-[:PERSONLINK]->persons
RETURN persons

但是如果我尝试我会得到一个错误:

but if I try I get an error:

Error: Type mismatch: nodeLinks already defined with conflicting type Collection<Node> (expected Node) (line 3, column 7)
"MATCH nodeLinks-[:PERSONLINK]->persons"

如何从路径中解压缩NODELINK类型的节点,以便对其进行进一步的MATCH查询?

How do I unpack the nodes of type NODELINK from the path in order to do further MATCH queries against them?

推荐答案

尝试这种方法……有点骇人听闻,但是直到进行放松操作为止,它将起作用.

Try this one... kind of hacky but until there's an unwind operation, it will work.

MATCH path=(nl:NODELINK { linkId:'cc' })-[:LINK*]->(u:USER)
WITH [x in nodes(path) | id(x)] AS nodeLinkIds
MATCH (n1:NODELINK)
WHERE id(n1) in nodeLinkIds // this does efficient id lookups for the nodes in the list
MATCH n1-[:PERSONLINK]->persons
RETURN persons

这篇关于Neo4j Cypher:如何从路径中解包节点以允许进一步匹配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆