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

查看:13
本文介绍了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's)进行进一步匹配,如下所示:

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?

推荐答案

试试这个……有点麻烦,但直到有一个 unwind 操作,它才会工作.

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天全站免登陆