neo4j如何配合两个火柴 [英] neo4j how to work with two match

查看:57
本文介绍了neo4j如何配合两个火柴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个查询.

第一个查询是

match (user)-[r:CreatesChat]-(chatitems)

第二个查询是

match (chatitems)-[r:PartOf]-(teamschat)-[s:OwnedBy]-()

我想从第一个查询中返回前3个用户

I want to return the first 3 users from the first query

从第二个查询中返回前三支球队

And to return the first 3 teams from the second query

目标是检查第一个查询的用户是否具有第二个查询的团队

The goal is to check if users from first query have the teams of second query

我的neo4j查询是

match (user)-[r:CreatesChat]-(chatitems)
with user.id as uid,chatitems.id as chatid
order by uid desc
with collect([uid])[..3] as users,collect([chatid])[..3] as chats
UNWIND users AS idusers
match (chatitems)-[r:PartOf]-(teamschat)-[s:OwnedBy]-()
return idusers

此查询返回

在1360毫秒内返回了133239行,显示了前1000行

但是我执行查询

match (user)-[r:CreatesChat]-(chatitems)
with user.id as uid,chatitems.id as chatid
order by uid desc
with collect([uid])[..3] as users,collect([chatid])[..3] as chats
UNWIND users AS idusers
return idusers

返回的iduser是正确的

idusers returned are right

在539毫秒内返回了3行.

如何关联这两个查询?

推荐答案

我认为您想同时收集排名前3位的用户和排名前3位的团队,然后对每个集合进行分解.像这样:

I think you want to collect both the top 3 users and the top 3 teams and then unwind over each collection. Something like this:

MATCH (user:User)-[:CreatesChat]->(chatitems:Chat)
WITH user ORDER BY user.id DESC LIMIT 3
WITH collect(user) AS users
MATCH (chatitems:Item)-[:PartOf]->(teamsChat:Team)-[:OwnedBy]-()
WITH users, teamsChat ORDER BY teamsChat.id DESC LIMIT 3
WITH users, collect(teamsChat) AS teams
UNWIND users AS user
UNWIND teams AS team
MATCH p=(chatitems:Item)-[:PartOf]-(team)-[:OwndedBy]-(user)
RETURN p

这篇关于neo4j如何配合两个火柴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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