我有一组作者和一组文章。它们是使用: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的文章,并根据文章数量找到排名前10的作者。我试过一堆不同的东西,但还是没有进展。任何帮助都将不胜感激。
问候你,理查德
发布于 2015-03-10 04:00:20
我认为这将会起作用:
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)https://stackoverflow.com/questions/28946851
复制相似问题