2013-05-09 27 views
6

我想将两个请求组合成一个查询,我不确定在单个密码查询中使用2个匹配语句时会发生什么。如何在密码查询中使用两条匹配语句

说我有一个朋友的列表,我希望看到我的朋友列表中的每个他们的叔叔和兄弟姐妹列在一个集合。我可以有两个可以完成这项工作的比赛陈述吗?例如

match friends-[:childOf]->parents-[:brother]->uncles 
    , friends-[:childOf]->parents<-[:childOf]-siblings 
return friends, collect(siblings), collect(uncles) 

但是,如果我做这样的查询,它总是返回没有结果。

+2

你能通过http://console.neo4j.org/分享一个示例图吗? – 2013-05-09 15:43:52

回答

7

既然你已经在你的第一场比赛类选择父母,你可以这样做 -

match friends-[:childOf]->parents-[:brother]->uncles 
with friends, parents, uncles 
match parents<-[:childOf]-siblings 
return friends, collect(siblings), collect(uncles) 
1

你可能想使一些可选的关系。例如,如果找到兄弟但没有找到任何叔叔,则该查询将返回null,因为它不满足两个匹配子句。如果您将结束关系设为可选,那么您不必完全满足这两个条款以返回数据。所以:

match friends-[:childOf]->parents-[?:brother]->uncles 
    , friends-[:childOf]->parents<-[?:childOf]-siblings 
return friends, collect(siblings), collect(uncles)