0

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 .

1 Answer 1

1

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

3
  • how is the peroformance on this query. Is this recommneded over using an index? We would be querying across all articles... Nov 9, 2012 at 12:15
  • node(*) is usually not recommended for big datasets... if you have an index for users you could use that as a start point. Nov 9, 2012 at 19:43
  • so I take it I should create a numeric lucene index for each post, updating/incrementing it on each like? Does the REST API support this on Heroku? Nov 11, 2012 at 18:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.