相互计数的搜索列表(第2次尝试) [英] Search list with mutual count (2nd try)
问题描述
我创建了新的数据集来解释我想要的结果. 这是链接
I have created fresh dataset to explain my desired result. and here is the link
或者您可以使用密码触发此命令.
Or you can trigger this command using cypher.
create
(_6 {UserName:"dhansukh", UserProfileID:'1000', EMailID:'f@xyz.com'}),
(_5 {UserName:"dhruv", UserProfileID:'516', EMailID:'e@xyz.com'}),
(_4 {UserName:"dharmistha", UserProfileID:'5262', EMailID:'d@xyz.com'}),
(_3 {UserName:"dinesh", UserProfileID:'995', EMailID:'c@xyz.com'}),
(_2 {UserName:"dharmesh", UserProfileID:'502', EMailID:'b@xyz.com'}),
(_1 {UserName:"manish", UserProfileID:'1', EMailID:'a@xyz.com'}),
_1-[:friends {ApprovalStatus: 1} ]->_2,
_1-[:friends {ApprovalStatus: 1} ]->_3,
_1-[:friends {ApprovalStatus: 2} ]->_5,
_2-[:friends {ApprovalStatus: 1} ]->_3,
_2-[:friends {ApprovalStatus: 1} ]->_5,
_3-[:friends {ApprovalStatus: 1} ]->_4
现在我正在尝试查询,但是没有得到预期的结果.
Now I am trying following query, but it is not given me my expected result.
START me=node:node_auto_index(UserProfileID = '1'), other=node(*)
MATCH pMutualFriends=me-[r?:friends]-mf-[r1:friends]-other
WHERE other.UserName =~ '(?i)dh.*' AND other.UserProfileID <> 1
RETURN other.UserProfileID, other.UserName, r.ApprovalStatus, COUNT(pMutualFriends) AS mutualCount
在上面的结果集中,我得到了重复的记录(由于ApprovalStatus),如果我删除了?从关系来看,它仅显示链接的节点,但我希望所有节点均以"dh"开头.节点6也丢失了,不知道为什么?在某些情况下,相互计数也显示错误.相互计数中只有那个具有ApprovalStatus = 1的节点才应考虑在内,例如登录节点(例如,节点1)和搜索节点都具有关系的属性ApprovalStatus =1.
In the above result set, I have get duplicate records, (due to ApprovalStatus), If I remove ? from relationship, it just shows linked node only, but I want all nodes started with 'dh'. node 6 also missing, don't know why? mutual count also showing wrong in some case. Only that node should be consider in mutual count which is has ApprovalStatus = 1. like login node (eg. node 1) and search nodes both have relationship's property ApprovalStatus = 1.
我的预期结果集:
EDIT : My expected result set :
UserProfileID UserName ApprovalStatus MutualCount
------------- -------- -------------- -----------
502 dharmesh 1 2 (node 3 & 5 )
516 dhruv 2 1 (node 2)
5262 dharmistha null 1 (node 3)
1000 dhansukh null 0
我正在更新图像以便清晰理解.
EDIT : I am updating image for clear understanding.
最近20到25天,我一直在遭受此问题的困扰,但没有找到适当的解决方案,我不知道问题出在哪里.我已经在stackoverflow上多次发布此问题. 这是链接,和此以及其他更多内容.
I am suffering from this issue last 20-25 days, and not getting proper solution, I don't know where is the problem. I have already post this problem many times on stackoverflow. here is the link, and this and this and many more.
推荐答案
正如我在评论中所说,尝试同时查询已连接和已断开连接的节点似乎不是一个好主意.
As I said in my comment, trying to query for connected and disconnected nodes at the same time doesn't seem to be a good idea.
如果只需要连接的节点,请尝试以下查询:
If you want only connected nodes, try the following query :
START me=node:node_auto_index(UserName = 'manish')
MATCH me-[:friends]-mf-[:friends]-other, me-[r?]-other
WHERE other.UserName! =~ '(?i)dh.*'
RETURN DISTINCT ID(other), r.ApprovalStatus AS status, count(mf) AS mutual, ID(me)
ORDER BY mutual DESC , status ASC
请注意,我必须在match子句中添加另一个模式,因为您的批准状态是在(me)和(other)之间,而不是在(me)和(共同朋友)之间,这就是您正在做的事情!
Please note that I had to add another pattern in the match clause, because your approval status is between (me) and (other), and not between (me) and (mutual friend), which is what you were doing!
这将返回预期答案的前三行,而忽略dhansukh.
This will return the first 3 lines of your expected answer and ignores dhansukh.
这篇关于相互计数的搜索列表(第2次尝试)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!