2015-03-02 19 views
1

我的文章和作者的圖形Neo4j的節點列表。我想找到最出版的作者。然後我想找到每篇文章的合着者名單。其目的是確定哪些合作作者的最頻繁合作與最有成效的作者。發現其中有最關係回到另一個節點

我是新來的暗號,我有以下的最可怕的命令確實是低效的。有沒有更好的方法來進行搜索?

我也想讓他們玩的結果,所以最好是返回作爲集合共同作者的名單?

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 

回答

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) 
+0

非常感謝 – 2015-03-03 13:28:32

相關問題