联接结果集 [英] Join result set

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

问题描述

我希望互相计数拥有友情的朋友.我已经为每个用户创建了节点,并创建了具有它们之间属性的关系.根据以下查询,我已经找到了想要的结果.在此测试案例中,我的登录用户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应该返回所有记录,并与2&第三结果集.

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也是me朋友的情况.

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天全站免登陆