具有相互计数的搜索列表(第二次尝试)

2024-01-31

我创建了新的数据集来解释我想要的结果。 这是link http://console.neo4j.org/r/dxwc8z

或者您可以使用 cypher 触发此命令。

create 
(_6  {UserName:"dhansukh", UserProfileID:'1000', EMailID:'[email protected] /cdn-cgi/l/email-protection'}),
(_5  {UserName:"dhruv", UserProfileID:'516', EMailID:'[email protected] /cdn-cgi/l/email-protection'}),
(_4  {UserName:"dharmistha", UserProfileID:'5262', EMailID:'[email protected] /cdn-cgi/l/email-protection'}),
(_3  {UserName:"dinesh", UserProfileID:'995', EMailID:'[email protected] /cdn-cgi/l/email-protection'}),
(_2  {UserName:"dharmesh", UserProfileID:'502', EMailID:'[email protected] /cdn-cgi/l/email-protection'}),
(_1  {UserName:"manish", UserProfileID:'1', EMailID:'[email protected] /cdn-cgi/l/email-protection'}),
_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

现在我正在尝试以下查询,但它没有给我预期的结果。

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。

EDIT :我的预期结果集:

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 :我正在更新图像以便清楚理解。

我在过去 20-25 天里遇到了这个问题,但没有得到适当的解决方案,我不知道问题出在哪里。我已经在 stackoverflow 上多次发布过这个问题了。 这里是link https://stackoverflow.com/questions/17878498/neo4j-search-list-with-mutual-count?noredirect=1#comment26138278_17878498, and this https://stackoverflow.com/questions/17917884/join-result-set/17933098?noredirect=1#17933098 and this https://stackoverflow.com/questions/17917508/neo4j-invalid-query-error-occured/17924225?noredirect=1#17924225还有很多。


正如我在评论中所说,尝试同时查询连接和断开连接的节点似乎不是一个好主意。

如果您只需要连接的节点,请尝试以下查询:

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

请注意,我必须在匹配子句中添加另一个模式,因为您的批准状态是在(我)和(其他)之间,而不是在(我)和(共同的朋友)之间,而这正是您所做的!

这将返回您预期答案的前 3 行并忽略 dhansukh。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

具有相互计数的搜索列表(第二次尝试) 的相关文章

随机推荐