我创建了新的数据集来解释我想要的结果。
这是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还有很多。