Join result set

后端 未结 1 839
陌清茗
陌清茗 2021-01-28 18:58

I want mutual count of my friends with friendship status. I have created nodes for each user and created relationship with properties between them. I have found my desired resul

相关标签:
1条回答
  • 2021-01-28 19:43

    When you query a graph db, you should start with the piece of specific data that you know and work outward on the graph from there. Using START n=node(*) ... is very expensive: You are returning the entire list across the entire graph of users. That is not what you want, though, as you only want those that are connected to the user with UserID=1.

    START me=node:node_auto_index(UserID = '1')
    MATCH me-[r:FRIENDS]-friend-[r1:FRIENDS]-other
    WHERE other.FirstName =~ "(?i)dh.*" AND other.UserID <> 1
        AND r.ApprovalStatus = 1 AND r1.ApprovalStatus = 1
        AND NOT (me-[:FRIENDS]-> other)
    RETURN other.UserID, other.FirstName, COUNT(friend) AS MutualCount
    

    This finds all friends of friends (other) who have a FirstName that starts with dh and counts the number of mutual friends they share with me.

    I also added the clause AND NOT (me-[:FRIENDS]-> other) to remove the case of other also being a friend of me.

    0 讨论(0)
提交回复
热议问题