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

时间:2015-03-02 17:46:01

标签: neo4j cypher

我有一篇文章和作者的图表。我想找到发表最多的作者。然后我想找到每篇文章的共同作者名单。目的是找出哪些共同作者最频繁地与最富有成效的作者合作。

我是cypher的新手,我在下面有一个非常可怕的命令,效率非常低。有没有更好的方法来进行搜索?

我也想让他们玩结果,所以最好将共同作者列表作为集合返回吗?

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

1 个答案:

答案 0 :(得分:7)

我认为您可以通过保留查询中第一个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)