查找与另一个节点有最多关系的 neo4j 节点列表

Finding a list of neo4j nodes which have the most relationships back to another node

我有一个文章和作者的图表。我想找到发表最多的作者。然后我想找到每篇文章的合著者列表。目的是找出哪些合著者与最有成效的作者合作的频率最高。

我是 cypher 的新手,我有下面最糟糕的命令,它真的很低效。有没有更好的搜索方式?

我也想让他们玩弄结果,所以最好return合著者列表作为一个集合吗?

MATCH (author:Author)-[:WROTE]->(article:Article) WITH author, COUNT(article) as numberofarticles
ORDER BY numberofarticles DESC LIMIT 1
MATCH (:Author {id:author.id})-[:WROTE]->(article:Article)
MATCH (coauthor:Author)-[:WROTE]->(:Article {id:article.id}) WHERE NOT coauthor:id = author.id
RETURN COUNT(coauthor), article

我认为您可以通过保留查询中第一个 match 的文章来提高查询效率。

我想这可能就是您要找的东西。

MATCH (author:Author)-[:WROTE]->(article:Article) 
WITH author, COUNT(article) AS number_of_articles, collect(article) AS articles
ORDER BY number_of_articles DESC 
LIMIT 1
UNWIND articles AS article
MATCH (coauthor:Author)-[:WROTE]->(article)
WHERE coauthor <> author
RETURN article, collect(coauthor)