如何在Neo4J中获得相互关系?

yv5phkfx  于 2022-11-05  发布在  其他
关注(0)|答案(1)|浏览(136)

我有一个亲戚:

Keyword - PAID_BY -> App

在这里,我想按应用程序查找共有的关键字。
示例:

KW1   PAID_BY  App1
KW2   PAID_BY  App1
KW1   PAID_PY  App2
KW1   PAID_PY  App3
KW2   PAID_PY  App3

当我尝试查找App1与其他应用程序的共同关键字时,我应该会找到如下结果:

KW1 is mutual keyword between App1 and App2 
and KW1 and KW2 is mutual keyword between App1 and App3

下面是我的密码查询:

MATCH a1:App{id:$idSource} <- PAID_BY - k:Keyword - PAID_BY -> a2:App 
RETURN a1,
       a2,
       COUNT(DISTINCT k) AS mutualKeywordCount,
       COLLECT(DISTINCT k) AS mutualKeywords

我试过了,但效果不明显。有什么建议吗?
它应该作为App1的输入:

App1  App2 1 KW1
App1  App3 2 KW1,KW2

但看起来:

App1  App2 1 KW1
App1  App3 2 KW1,KW2
App1  App3 2 KW1,KW2
emeijp43

emeijp431#

DISTINCT也可以用在RETURN中。请尝试:

RETURN DISTINCT a1,
       a2,
       COUNT(DISTINCT k) AS mutualKeywordCount,
       COLLECT(DISTINCT k) AS mutualKeywords

相关问题