gpt4 book ai didi

neo4j - 当配对顺序在密码中不重要时查询唯一的节点对

转载 作者:行者123 更新时间:2023-12-01 08:05:59 25 4
gpt4 key购买 nike

我试图根据用户在此 graph 中的共同兴趣进行比较.
我知道为什么下面的查询会产生重复的对,但想不出在密码中避免它的好方法。有没有办法在不循环密码的情况下做到这一点?

neo4j-sh (?)$ start n=node(*) match p=n-[:LIKES]->item<-[:LIKES]-other where n <> other return n.name,other.name,collect(item.name) as common, count(*) as freq order by freq desc;
==> +-----------------------------------------------+
==> | n.name | other.name | common | freq |
==> +-----------------------------------------------+
==> | "u1" | "u2" | ["f1","f2","f3"] | 3 |
==> | "u2" | "u1" | ["f1","f2","f3"] | 3 |
==> | "u1" | "u3" | ["f1","f2"] | 2 |
==> | "u3" | "u2" | ["f1","f2"] | 2 |
==> | "u2" | "u3" | ["f1","f2"] | 2 |
==> | "u3" | "u1" | ["f1","f2"] | 2 |
==> | "u4" | "u3" | ["f1"] | 1 |
==> | "u4" | "u2" | ["f1"] | 1 |
==> | "u4" | "u1" | ["f1"] | 1 |
==> | "u2" | "u4" | ["f1"] | 1 |
==> | "u1" | "u4" | ["f1"] | 1 |
==> | "u3" | "u4" | ["f1"] | 1 |
==> +-----------------------------------------------+

最佳答案

为了避免出现 a--b 形式的重复项和 b--a ,您可以使用以下命令排除 WHERE 子句中的组合之一

WHERE ID(a) < ID(b)

进行上述查询
start n=node(*) match p=n-[:LIKES]->item<-[:LIKES]-other where ID(n) < ID(other) return n.name,other.name,collect(item.name) as common, count(*) as freq order by freq desc;

关于neo4j - 当配对顺序在密码中不重要时查询唯一的节点对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17096401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com