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 result as per following queries. In this test case my login userid=1, and I want to search those users which is started from letter 'dh'. so, my query is as follows.
1st Query : which is returned all users with specific given keyword.
--------------------------------------------------------------------
START other=node(*)
WHERE other.FirstName =~ "(?i)dh.*" AND other.UserID <> 1
WITH other, me=node:node_auto_index(UserID = '1')
RETURN other.UserID, other.UserName, other.FirstName, other.LastName, other.ImagePath
LIMIT 100;
This query returns me all users started with 'dh' Now, I want friendship status between my login user and this searched users. so, I have done to this as follows:
2nd Query : which is returned approvalstatus between user1 and other
--------------------------------------------------------------------
START me=node:node_auto_index(UserID = '1')
MATCH me-[myR:friends]-(x)
RETURN x.UserID, myR.ApprovalStatus
ORDER BY x.UserID
and finally, I need mutual friend count between user 1 and others as per following query.
3rd Query : which is returned mutual count between user1 and other
------------------------------------------------------------------
START me=node:node_auto_index(UserID = '1'), other=node(*)
MATCH pMutualFriends=me-[r:friends]-mf-[r1:friends]-other
WHERE r.ApprovalStatus = 1
AND r1.ApprovalStatus = 1
AND other.FirstName =~ "(?i)dh.*" AND other.UserID <> 1
RETURN other.UserID, COUNT(pMutualFriends) AS mutualCount
ORDER BY other.UserID
Now I want to join all of this query like we do in RDBMS. means result set 1st should return all records, join with 2nd & 3rd result set.
How do i do this?
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.This finds all friends of friends (
other
) who have a FirstName that starts withdh
and counts the number of mutual friends they share withme
.I also added the clause
AND NOT (me-[:FRIENDS]-> other)
to remove the case ofother
also being a friend ofme
.