Neo4j.rb:与用户有很多共同朋友的朋友之交

时间:2019-06-04 04:50:24

标签: neo4j cypher

我有1个节点和1个关系

节点-用户

基本上,我正在研究一种解决方案,以列出与用户有很多共同朋友的好友列表,而且高度互惠者将排在首位。

关系具​​有1个属性状态,应为1(表示用户是朋友,0表示连接请求正在等待处理)

  Neo4j::ActiveBase.new_query.match(n: {StayPal: { uuid: "005d-46de- 
  9ab4-b54aa7a92a8a" }}).break.match('(n)-[:connected_to {status: 1}]- 
  (mutual)-[:connected_to {status: 1}]-(friends_of_friends: 
  `StayPal`)').break.match('(n)-[:connected_to {status: 1}]-(mutual2)- 
  [:connected_to {status: 1}]- 
  (friends_of_friends)').return('friends_of_friends, mutual2')

密码查询:

MATCH (n:`StayPal` {uuid: {n_StayPal_uuid}}) MATCH (n)-[:connected_to 
{status: 1}]-(mutual)-[:connected_to {status: 1}]-(friends_of_friends: 
`StayPal`) MATCH (n)-[:connected_to {status: 1}]-(mutual2)- 
[:connected_to {status: 1}]-(friends_of_friends) RETURN 
friends_of_friends, mutual2

如果我做对了,请帮助我?我认为common2应该是数组,但它只给1个用户和1个friends_of_friend

1 个答案:

答案 0 :(得分:0)

希望这会有所帮助

MATCH (n:`StayPal` {uuid: {n_StayPal_uuid}})-[:connected_to {status: 1}]-(mutual)-[:connected_to {status: 1}]-(friends_of_friends: `StayPal`) 
RETURN DISTINCT friends_of_friends , COLLECT(DISTINCT mutual), COUNT(mutual) as mutualCount 
ORDER BY mutualCount DESC LIMIT 10