我想相互计算我的朋友的友谊状态。我为每个用户创建了节点,并创建了它们之间的属性关系。根据以下查询,我找到了我想要的结果。在这个测试用例中,我的登录用户 ID=1,我想搜索那些以字母 'dh' 开头的用户。所以,我的查询如下。
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;
这个查询返回我所有以'dh'开头的用户现在,我想要我的登录用户和这个搜索用户之间的友谊状态。所以,我这样做了如下:
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
最后,根据以下查询,我需要用户 1 和其他人之间的共同朋友计数。
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
现在我想像在 RDBMS 中一样加入所有这些查询。意味着结果集 1st 应该返回所有记录,加入 2nd & 3rd 结果集。
我该怎么做呢?