加入结果集 [英] Join result set

查看:21
本文介绍了加入结果集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想共同统计我的好友数量.我为每个用户创建了节点,并在它们之间创建了与属性的关系.我根据以下查询找到了我想要的结果.在这个测试用例中,我的登录用户 ID=1,我想搜索那些以字母 'dh' 开头的用户.所以,我的查询如下.

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;

此查询返回所有以 'dh' 开头的用户现在,我想要我的登录用户和搜索到的用户之间的友谊状态.所以,我这样做了如下:

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

最后,根据以下查询,我需要用户 1 和其他人之间的共同好友数.

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

现在我想像在 RDBMS 中一样加入所有这些查询.意味着结果集 1st 应返回所有记录,与 2nd & 连接第三个结果集.

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.

我该怎么做?

推荐答案

当您查询图形数据库时,您应该从您知道的特定数据开始,然后从那里向外处理图形.使用 START n=node(*) ... 非常昂贵:您将返回整个用户图的整个列表.但是,这不是您想要的,因为您只想要那些连接到 UserID=1 的用户.

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

这将查找名字以dh开头的朋友(other)的所有朋友,并计算他们与me共享的共同朋友的数量代码>.

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.

我还添加了子句 AND NOT (me-[:FRIENDS]-> other) 以去除 other 也是 的朋友的情况我.

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

这篇关于加入结果集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆