incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Vander Wilt <>
Subject Re: Get the 20 posts, of the last seven days, ordered by number of hits
Date Mon, 22 Jul 2013 22:11:58 GMT
If your "hit" document includes the post date, you could map with `emit([hit.post_date, hit.post_id])`
and reduce with `_count`. Then you when queried with `?group=exact` you would have total hits
per post and you could prune the results using startkey to last 7 days. You would still need
to order all the recent matches yourself before limiting to 20 posts however. Assuming the
number of posts in a week is not enormous it seems reasonable.


On Jul 22, 2013, at 10:32 AM, Filippo Fadda wrote:

> OK, this answered to my question:
> It is never possible to query by criteria A and then sort by criteria B in CouchDB.
> So I have to get posts in a data range, then sort them by number of hits myself.
> -Filippo
> On Jul 22, 2013, at 6:25 PM, Filippo Fadda wrote:
>> Let's suppose I have a blog and I want display the popular posts, where popular means:
the 20 posts, of the last seven days, ordered by number of hits.
>> To avoid conflicts I don't save the number of hits in the post itself, but I emit
a new document every time a generic user displays a post.
>> Even using view collation I don't get a solution for this problem.
>> -Filippo

View raw message