1

我需要你在 neo4j 项目中的帮助。我有两个节点作者和文章。它们之间的关系是

(author:Author)-[:WRITES]->(article:Article)

一篇文章可以由多个作者撰写。所以我想计算哪些是合作最多的前 5 位作者(与不同的作者)。另外,我想返回作者姓名和合作次数。我尝试了以下方法,但没有奏效。

MATCH (article:Article)<-[:WRITES]-(author:Author)
with article, collect(distinct author.name) as authors
RETURN authors,size(authors)-1 as numberofcollaborations
ORDER BY numberofcollaborations DESC
LIMIT 5; 

有任何想法吗?

4

1 回答 1

1

您可以使用路径模式获取每篇文章的贡献者,然后按作者聚合:

MATCH (author:Author)-[:WRITES]->(article:Article)<-[:WRITES]-(coauthor:Author)
WITH author, 
     size(collect(distinct coauthor)) as numberofcollaborations 
     ORDER BY numberofcollaborations 
     DESC LIMIT 5
RETURN author.name as author, 
       numberofcollaborations
于 2020-12-24T00:06:45.350 回答