使用多个match子句不会在neo4j密码查询中返回任何结果 [英] using multiple match clauses doesn't return any result in neo4j cypher query

查看:360
本文介绍了使用多个match子句不会在neo4j密码查询中返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行以下两个查询,并且得到了一些结果.

I am executing the following two queries and i am getting some result.

第一个查询

START 
person=node:NODE_TYPE(NODE_TYPE='PERSON') 
MATCH 
(person)-[?:contacts]->(var1)-[?:addresses]->(var2)-[?:details]->(var3)-[?:items]->(var4)-[?:items]->(var5)-[?:value]->(var6) 
WHERE 
var2.`#nodeId` ='at0000' and var3.`#nodeId` ='at0001' and var4.`#nodeId` ='at0002' and var5.`#nodeId` ='at0028' and var6.`value` =~'address.*' 
return distinct person;

第二个查询

START 
person=node:NODE_TYPE(NODE_TYPE='PERSON') 
MATCH 
(person)-[?:contacts]->(var1)-[?:addresses]->(var2)-[?:details]->(var3)-[?:items]->(var4)-[?:value]->(var5) 
WHERE 
var2.`#nodeId` ='at0000' and var3.`#nodeId` ='at0001' and var4.`#nodeId` ='at0009' and var5.`value` =~'india.*' 
return distinct person;

但是,当我将两个查询合并到一个查询中以同时满足这两个条件的人时,它就不起作用了.

But when I combine the two queries to a single query to get persons that match both these conditions, it isn't working.

组合查询为

START 
person=node:NODE_TYPE(NODE_TYPE='PERSON')  
MATCH 
(person)-[?:contacts]->(var1)-[?:addresses]->(var2)-[?:details]->(var3)-[?:items]->(var4)-[?:items]->(var5)-[?:value]->(var6) , (person)-[?:contacts]->(var7)-[?:addresses]->(var8)-[?:details]->(var9)-[?:items]->(var10)-[?:value]->(var11) 
WHERE 
var2.`#nodeId` ='at0000' and var3.`#nodeId` ='at0001' and var4.`#nodeId` ='at0002' and var5.`#nodeId` ='at0028' and var6.`value` =~'address.*' and 
var8.`#nodeId` ='at0000' and var9.`#nodeId` ='at0001' and var10.`#nodeId` ='at0009' and var11.`value` =~'india.*' 
return distinct person;

此查询返回一个空的迭代器.

This query return an empty iterator.

我用'逗号'组合了MATCH条件,并用'and'组合了WHERE条件. 这有什么问题吗?

I used 'comma' to combine the MATCH conditions and 'and' to combine the WHERE conditions. Is there any problem in this?

(我正在实现查询构建器来构建密码查询.我必须检查多个条件匹配项.执行此操作的最佳方法是什么?)

(I am implementing a query builder to build cypher query. I have to check multiple condition matches. What is the best way to do this?)

Neo4j 1.9M04

推荐答案

您可能会遇到var7无法分配给同一节点.

You may be running into the "identifier uniqueness" condition described here (see first post by Michael Hunger). If you got a match on the same (person) node and have only 1 :contacts relation from there, then the identifier var1 is "using up" the connected node in this match and var7 can't be assigned to the same node.

换句话说,由match语句找到的节点只能由同一match语句中的一个标识符使用.

In other words, a node found by a match statement can only be used by one identifier within the same match statement.

您可以尝试使用WITH子句,然后再使用另一个MATCH来解决此问题.

You can try to use a WITH clause instead followed by another MATCH to work around this issue.

START 
person=node:NODE_TYPE(NODE_TYPE='PERSON') 
MATCH 
(person)-[?:contacts]->(var1)-[?:addresses]->(var2)-[?:details]->(var3)-[?:items]->(var4)-[?:items]->(var5)-[?:value]->(var6) 
WHERE 
var2.`#nodeId` ='at0000' and var3.`#nodeId` ='at0001' and var4.`#nodeId` ='at0002' and var5.`#nodeId` ='at0028' and var6.`value` =~'address.*' 
with distinct person
MATCH 
(person)-[?:contacts]->(var1)-[?:addresses]->(var2)-[?:details]->(var3)-[?:items]->(var4)-[?:value]->(var5) 
WHERE 
var2.`#nodeId` ='at0000' and var3.`#nodeId` ='at0001' and var4.`#nodeId` ='at0009' and var5.`value` =~'india.*' 
return distinct person;

这篇关于使用多个match子句不会在neo4j密码查询中返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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