neo4j - user suggestion with mutual count

纵然是瞬间 提交于 2019-12-13 08:14:56

问题


I have created 5 nodes in neo4j as follows.

Node 1 {userid:1000, username: A, someOtherProperties...}
Node 2 {userid:2000, username: B, someOtherProperties...}
Node 3 {userid:3000, username: c, someOtherProperties...} 
Node 4 {userid:4000, username: D, someOtherProperties...} 
Node 5 {userid:5000, username: E, someOtherProperties...} 

Node 1 connected with Node 2 & 3, and Node 2 connected with node 1, 3, 4

1 -> 2
1 -> 3
2 -> 1
2 -> 3
2 -> 4
3 -> 4

Now I want user suggestion for node 1 which contain those node which is not connected with it self with mutual count. I want result like this.

node id  userid  username  mutual count
-------  ------  --------  -------------
4    4000    D         2             (which is node 2 & 3)
5    5000    E         0    

I had tried cypher query, but I didn't get success.


回答1:


Please try

START user=node:node_auto_index(name='A'), f=node(*) 
MATCH user-[r?:FRIEND*1..2]->(f) 
WITH DISTINCT r AS friendRelation,f 
RETURN count(friendRelation),f

Which will give you the number of friend relations to every other node with a depth 2 (friend of a friend)



来源:https://stackoverflow.com/questions/17721173/neo4j-user-suggestion-with-mutual-count

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!