MonkeyBonkey
MonkeyBonkey

Reputation: 47881

support a "Most Popular" query in neo4j

If I wanted to do a "most liked" article query in neo 4j, where "liked" is a relationship between user and article, would the best way be to:

  1. Keep a totalLikes count property in the article itself and do a sort on that property in a cypher query? That property would be updated everytime somone liked an article.

Or

  1. Keep an index with totalLikes for each article. I would have to delete and re-add the index entry every time the article was liked.

I think I read in the documentation that queries cannot be sorted on total relationships count .

Upvotes: 0

Views: 261

Answers (1)

Eve Freeman
Eve Freeman

Reputation: 33155

So, you can do:

start user=node(*)
match user-[rel:liked]->article
return count(rel) as likeCount, article
order by likeCount desc;

http://console.neo4j.org/r/5do0qr

Upvotes: 1

Related Questions