我想做一个将占用所有用户的查询(没有像用户ID这样的前置条件),并找到常见的类似路径 s 。 (例如前10名用户流)
例如:
用户u1有事件:a,b,c,d
用户u2有事件:b,d,e
每个事件都是具有属性事件类型
的节点结果应该如下:
[a,b,e] - 100 users
[a,c,f] -80 users
[b,d,t]- 50 users
.......
生成结果中第一个聚合行的数据可以是例如:
用户1: a,b ,c, e
用户2: a,b,e ,f
.........
用户100: a ,c,t, b ,g, e
我想知道这个链接是否有帮助: http://neo4j.com/docs/stable/rest-api-graph-algos.html#rest-api-execute-a-dijkstra-algorithm-with-equal-weights-on-relationships
答案 0 :(得分:3)
这是一个Cypher查询,它返回用户1和用户2共有的所有Event
个节点(在一行中):
MATCH (u1:User {id: 1}) -[:HAS]-> (e:Event) <-[:HAS]- (u2:User {id: 2})
RETURN u1, u2, COLLECT(e);
[MichaelHunger补充说;由cybersam修改]对于您的其他问题,请尝试:
// Specify the user ids of interest. This would normally be a query parameter.
WITH [1,2,3] as ids
MATCH (u1:User) -[:HAS]-> (e:Event)
// Only match events for users with one of the specified ids.
WHERE u1.id IN ids
// Count # of distinct user ids per event, and count # of input ids
WITH e, size(collect(distinct u1.id)) as n_users, size(ids) AS n_ids
// Only match when the 2 counts are the same
WHERE n_users = n_ids
RETURN e;