Neo4j 如何计算节点的不同计数

Neo4j 如何计算节点的不同计数,neo4j,cypher,neo4j-apoc,cypher-3.1,Neo4j,Cypher,Neo4j Apoc,Cypher 3.1,我需要你在neo4j项目中的帮助。我有两个节点:作者和文章。它们之间的关系是 (author:Author)-[:WRITES]->(article:Article) 一篇文章可以由多个作者撰写。所以我想计算一下,哪五位作者的合作最多(与不同的作者)。此外,我还想返回作者姓名和合作数量。我试过下面的方法,但没用 MATCH (article:Article)<-[:WRITES]-(author:Author) with article, collect(distinct auth

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

(author:Author)-[:WRITES]->(article:Article)
一篇文章可以由多个作者撰写。所以我想计算一下,哪五位作者的合作最多(与不同的作者)。此外,我还想返回作者姓名和合作数量。我试过下面的方法,但没用

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; 

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

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

MATCH(author:author)-[:WRITES]->(article:article)非常感谢!它起作用了!!你让我开心!:)