简体   繁体   中英

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM