Neo4j匹配不返回行

时间:2016-07-12 04:10:42

标签: neo4j cypher

我使用neo4j cypher

我有两个关系

MATCH (user)-[:CreatesChat]-(chatitems)
MATCH (chatitems)-[:PartOf]->(teamsChat)-[:OwnedBy]-()

通过第一个查询,我获得了用户和聊天项目。 在第二次询问中,我得到了团队。

我想检查用户第一次查询是否有第二个查询的团队。

我写了这个查询

MATCH (user)-[:CreatesChat]-(chatitems)
WITH user as users ,chatitems as chats ORDER BY chatitems.id DESC LIMIT 10
WITH users,collect(chats) AS chats1
with users, chats1, collect(users) as users1
MATCH (chatitems)-[:PartOf]->(teamsChat)-[:OwnedBy]-()
WITH users1, chats1,teamsChat ORDER BY teamsChat.id DESC LIMIT 3
WITH users1, chats1, collect(teamsChat) AS teams
UNWIND teams AS team
UNWIND chats1 AS chatid
unwind users1 as userid
return userid, chatid, team

结果

userid,chatid,team
"{""id"":789}","{""id"":65090}","{""id"":62531}"
"{""id"":789}","{""id"":65090}","{""id"":62531}"
"{""id"":656}","{""id"":65092}","{""id"":62531}"

为了检查用户是否有第二场比赛的队伍,我添加了

MATCH (user)-[:CreatesChat]-(chatitems)
WITH user as users ,chatitems as chats ORDER BY chatitems.id DESC LIMIT 10
WITH users,collect(chats) AS chats1
with users, chats1, collect(users) as users1
MATCH (chatitems)-[:PartOf]->(teamsChat)-[:OwnedBy]-()
WITH users1, chats1,teamsChat ORDER BY teamsChat.id DESC LIMIT 3
WITH users1, chats1, collect(teamsChat) AS teams
UNWIND teams AS team
UNWIND chats1 AS chatid
unwind users1 as userid
MATCH p=(chats)-[:PartOf]-(teams)-[:OwndedBy]-(users)
RETURN p

此查询不返回任何行。

我如何使用之前在MATCH中获得的users1,chats1和团队

MATCH p =(聊天) - [:PartOf] - (团队) - [:OwndedBy] - (用户)

编辑:

我查了一些问题。

我有查询(聊天和团队)

MATCH (chatitems1)-[:PartOf]->(teamsChat)-[:OwnedBy]-()
WITH chatitems1 , teamsChat ORDER BY teamsChat.id DESC LIMIT 3
return chatitems1,teamsChat

chatitems1,teamsChat
"{""id"":64990}","{""id"":62531}"
"{""id"":63247}","{""id"":62531}"
"{""id"":60211}","{""id"":58852}"

执行查询后

MATCH (user)-[:CreatesChat]-(chatitems)
WITH user ORDER BY user.id DESC LIMIT 10
MATCH (chatitems1)-[:PartOf]->(teamsChat)-[:OwnedBy]-()
WITH user,chatitems1 , teamsChat ORDER BY teamsChat.id DESC LIMIT 3
return user,chatitems1,teamsChat

我想看到用户查询1和chatitems,teamsChats查询2.结果是

user,chatitems1,teamsChat
"{""id"":65098}","{""id"":64990}","{""id"":62531}"
"{""id"":65098}","{""id"":63247}","{""id"":62531}"
"{""id"":65097}","{""id"":64990}","{""id"":62531}"

neo4j是产品笛卡儿吗?

0 个答案:

没有答案