我有一组作者和一组文章。它们使用[:WROTE]关系相关。一篇文章可以有一个或多个作者,作者可以写一篇或多篇文章。
我想知道,就作者数量而言,前十篇文章中有多少是作为共同作者列出效率最高的作者。
我可以使用
找到最佳作者MATCH (author:Author)-[:WROTE]->(article:Article)
WITH author, COUNT(article) as numberofarticles, collect(article) as articles
ORDER BY numberofarticles DESC LIMIT 1
RETURN author, numberofarticles, EXTRACT(n in articles | n.title) AS extracted
同样,我可以使用
找到作者方面的前10篇文章MATCH (author:Author)-[:WROTE]->(article:Article)
WITH article, COUNT(author) as numberofauthors
ORDER BY numberofauthors DESC LIMIT 10
RETURN article.title, numberofauthors
然而,我被困在这里。因为匹配是相同的,我创建了两个集合,即作者集合和文章集合
MATCH (author:Author)-[:WROTE]->(article:Article)
WITH collect(author) as authors, COUNT(author) as numberofauthors, collect(article) as toparticles, COUNT(article) as numberofarticles
但是现在我不得不按照作者数排序收集前10篇文章,按文章数排序查找最佳作者。我尝试了很多不同的东西,但我没有接近。任何帮助将不胜感激。
问候,理查德
答案 0 :(得分:0)
我认为这将有效:
MATCH (author:Author)-[:WROTE]->(article:Article)
WITH author, count(article) ORDER BY count(article) DESC
WITH collect(author)[0] AS top_author
MATCH (article:Article)<-[:WROTE]-(author:Author)
WITH top_author, article, count(author) ORDER BY count(author) DESC
WITH top_author, collect(article)[0..10] AS top_10_article
MATCH top_author-[rel:WROTE]->top_10_article
RETURN count(rel)