gpt4 book ai didi

Neo4j Cypher : How do you unpack nodes from a path to allow for further matching?

转载 作者:行者123 更新时间:2023-12-04 07:38:20 29 4
gpt4 key购买 nike

这个问题是对here问题的关注

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

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

检索路径后,我想针对该路径中的节点(NODELINK的节点)做进一步的匹配,如下所示:
MATCH path=(nl:NODELINK { linkId:'cc' })-[:LINK*]->(u:USER)
WITH nodes(path) AS nodeLinks
MATCH nodeLinks-[:PERSONLINK]->persons
RETURN persons

但是,如果我尝试我得到一个错误:
Error: Type mismatch: nodeLinks already defined with conflicting type Collection<Node> (expected Node) (line 3, column 7)
"MATCH nodeLinks-[:PERSONLINK]->persons"

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

最佳答案

尝试这种...有点hacky,但是直到进行放松操作为止,它将起作用。

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 : How do you unpack nodes from a path to allow for further matching?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22184924/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com