密码:在多个交叉链表中旅行 [英] Cypher: Travel in several crossed chained list

查看:68
本文介绍了密码:在多个交叉链表中旅行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户图. 在此图中,它们也是活动(节点).每个用户都有其活动的链表:

I have a graph with users. In this graph their are also activities (nodes). Each user have a chained list of its activities :

(user)-[:NEXT_ACTIVITY*]->(activities)

但是有一个棘手的部分:一个活动可以由2个用户拥有.因此,我在NEXT_ACTIVITY关系中设置了具有用户ID的属性"idUser".这样才能找到1个用户的所有活动.

But there is one tricky part : an activity can be owned by 2 users. So I set a property "idUser" in my NEXT_ACTIVITY relation, with the ID of the user. This is how I can find all activities for 1 user.

START user=node:users('name:JohnDoe')
MATCH (user)-[rel:NEXT_ACTIVITY*]->(activities)
WHERE ALL (r in rel WHERE r.idUser = id(user))

我的问题是我不知道如何使用该系统为多个用户进行活动.如何旅行几个用户的链表,并确保所有 NEXT_ACTIVITY 图旅行都属于这些用户?

My problem is that I don't know how to get activities for several users with this system. How can I travel chained list of several users, and being sure that all NEXT_ACTIVITY the graph travel belongs to these users ?

用例:我想获得用户及其朋友的活动.

The use case : I want to get activities of a user and its friends.

关于, 拉斐尔

Ps:活动可以由2个用户拥有的原因是,如果 A B 的墙上发布,则是A和B的活动. /p>

Ps: the reason why an activity can be owned by 2 users is that if A publish on B's wall, it's an activity for A and B.

推荐答案

由于关系的长度为0,因此您可以首先获取该用户的所有朋友(例如name ='u1'),其中也包括该用户. .1,然后为他们每个人进行所有活动.

You can first get all friends of the user(say name='u1'), that includes the user as well since the length of the relationship is 0..1, and then for each of them, get all activities.

Match u:User-[:FRIEND*0..1]->friend:User
Where u.name = 'u1'
With friend 
Match friend-[rel:NEXT_ACTIVITY*]->activity
Where all(r in rel where r.idUser = id(friend))
Return friend.name, collect(activity.name)

如果您只需要所有活动而与用户无关,则请返回不同的activity.name"

if you just need all activities regardless of users, then "Return distinct activity.name"

这篇关于密码:在多个交叉链表中旅行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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