Cypher LinkedList 按索引匹配,但“不知道如何比较".反而 [英] Cypher LinkedList Match by index but "Don't know how to compare that." instead
问题描述
我在按索引进行 MATCH 时遇到问题,希望您能提供帮助.相关讨论可以在这篇文章中找到:Cypher Linked LIst: 如何取消移位并按索引替换
I am having trouble with MATCH by index and I am hoping you can help. Related discussion can be found at this post: Cypher Linked LIst: how to unshift and replace by index
首先,我运行以下 unshift 查询 3 次,以便用关系和节点填充链表
First I run the following unshift query three times in order to populate the linked list with relationships and nodes
MATCH (p {id: '123A'})
OPTIONAL MATCH (p)-[r:Foo]->(c)
WITH p, r, COLLECT(c) AS cs
MERGE (cNew {
id:'456B' // and '789C' and 'WXYZ'
})
CREATE (p)-[rNew:Foo {
isFavorite:false,
isOpen:false,
currenttab:'all',
currentdate:2015-10-30T07:00:00.000Z
}]->(cNew)
FOREACH (x IN cs |
CREATE (cNew)-[:Foo {
isFavorite:r.isFavorite,
isOpen:r.isOpen,
currenttab:r.currenttab,
currentdate:r.currentdate
}]->(x)
DELETE r)
RETURN p, rNew, cNew
事后我可以使用这个查询获取输出,以便我可以看到我的链表数组中的关系标签 Foo 下有三个元素
Afterwords I can fetch the output with this query so that I can see that I have three elements in my linkedlist array under the relationship label Foo
MATCH ()-[r:`language-arts_ALLRESOURCES`]->() RETURN r
isFavorite false
isOpen false
currenttab all
currentdate 2015-10-30T07:00:00.000Z
isFavorite false
isOpen false
currenttab all
currentdate 2015-10-30T07:00:00.000Z
isFavorite false
isOpen false
currenttab all
currentdate 2015-10-30T07:00:00.000Z
然后我尝试使用这个密码查询来查询第一个索引
I then try to query the first index with this cypher query
MATCH (p { id:"123A" })
MATCH (p)-[:Foo*1]->()-[r:Foo]->(c)
RETURN c
但我想出了以下错误:
Don't know how to compare that. Left: [:Foo[8258]
{isFavorite:false,isOpen:false,currenttab:"all",currentdate:"2015-10-
30T07:00:00.000Z"}] ($colon$colon); Right: :Foo[8260]
{isFavorite:false,isOpen:false,currenttab:"all",currentdate:"2015-10-
30T07:00:00.000Z"} (RelationshipProxy)
我试着用这个查询来获取:
I tried fetching with this query:
MATCH (p { id:"123A" })
MATCH (p)-[:Foo*2]->(c)
RETURN c
这是返回的输出
id 789C // which is index 1
对于索引 1 是否应该使用整数 0 或 1 或 2 获取,我也有一些困惑,但我相信一旦我通过了不知道如何比较它"这一问题,这种困惑就可以解决.'错误.请帮助我指导如何通过索引有效获取并避免我上面列出的错误的正确方法.
I also have some slight confusion as to whether index 1 should be fetched with the integer 0 or 1 or 2 but that confusion I am sure can be sorted out once I get passed this 'Don't know how to compare that.' error. Please help me with guidance as to the right way to fetch effectively by index and avoid the error I listed above.
非常感谢您的帮助
** 注意**
阅读cybersam的回答后,我对上面提到的包含三个元素的链表结构进行了以下测试
After reading cybersam's answer, I have run the following tests on the linked list structure mentioned above that contains three elements
此查询返回索引 0 位置的子项:
This query returns the child at the index 0 position:
MATCH (p { id:'123A' })
MATCH (p)-[:Foo*0]->()-[r:Foo]->(c)
RETURN c
此查询返回索引 1 位置处的子项:
This query returns the child at the index 1 position:
MATCH (p { id:'123A' })
MATCH (p)-[:Foo]->()-[r:Foo]->(c)
RETURN c
此查询返回不知道如何比较".错误
This query returns the "Don't know how to compare that." error
MATCH (p { id:'123A' })
MATCH (p)-[:Foo*1]->()-[r:Foo]->(c)
RETURN c
此查询返回索引为 2 位置的子项:
This query returns the child at the index 2 position:
MATCH (p { id:'123A' })
MATCH (p)-[:Foo*2]->()-[r:Foo]->(c)
RETURN c
我假设最后一个适用于任何 >= 2
I am assuming this last one works for anything >= 2
推荐答案
Cypher 似乎对(据我所知)合法的 [:Foo*1]
语法感到困惑.如果你只是使用 [:Foo]
代替,它在逻辑上是等效的,你就可以避免这个错误.
Cypher seems to be confused by the (as far as I can tell) legal [:Foo*1]
syntax. If you just used [:Foo]
instead, which logically equivalent, you would have avoided the error.
但是,实际上,获取索引为 0 的孩子的方法是:
But, actually, the way to get the index 0 child is:
MATCH (p { id:"123A" })
MATCH (p)-[r:Foo]->(c)
RETURN c;
或者,要以更通用的方式获取 0 索引子项,这将起作用.这种通用模式应该总是适用于任何索引(通过将 0
替换为所需的索引),但是在使用 <代码>1代码>:
Or, to get the 0 index child in a more generic way, this will work. This generic pattern should always work for any index (by replacing 0
with the desired index), but there seems to be a bug (as stated above) in Cypher when using 1
:
MATCH (p { id:"123A" })
MATCH (p)-[:Foo*0]->()-[r:Foo]->(c)
RETURN c
我为此创建了 neo4j 问题 5799.
这篇关于Cypher LinkedList 按索引匹配,但“不知道如何比较".反而的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!