You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Seggy Umboh <se...@gmail.com> on 2009/10/06 03:36:39 UTC

Getting a top 10 list by a calculated value

Hello everyone,
I've been reading about couchdb and just started playing around with it, and
I am wondering, in the typical blog/comment example application, is it
possible to get a list of the Top 10 commenters? It is trivial to write a
view to get the number of comments for each commenter, but now I want to
sort the result of that view by the values....

Re: Getting a top 10 list by a calculated value

Posted by Paul Davis <pa...@gmail.com>.
Apologies for not thinking the first time.

There's an example on the wiki [1] called "Retrieve the top N tags"
that does that you want. It only works because you know what N is a
priori though.

HTH,
Paul Davis

[1] http://wiki.apache.org/couchdb/View_Snippets

On Mon, Oct 5, 2009 at 9:36 PM, Seggy Umboh <se...@gmail.com> wrote:
> Hello everyone,
> I've been reading about couchdb and just started playing around with it, and
> I am wondering, in the typical blog/comment example application, is it
> possible to get a list of the Top 10 commenters? It is trivial to write a
> view to get the number of comments for each commenter, but now I want to
> sort the result of that view by the values....
>

Re: Getting a top 10 list by a calculated value

Posted by Zachary Zolton <za...@gmail.com>.
Perhaps even updating the count using this new 0.10 feature:

http://wiki.apache.org/couchdb/How_to_intercept_document_updates_and_perform_additional_server-side_processing

function(userDoc, req) {
  userDoc.blog_count = req.query.blog_count;
  return [userDoc, 'mission accomplished!'];
}

On Mon, Oct 5, 2009 at 11:10 PM, kowsik <ko...@gmail.com> wrote:
> If you have the user and comment as separate docs (with the user_id in
> the comment doc), then the simple way is to update the user doc each
> time s/he makes a comment with a count of the comments so far.
> Conflict resolution is a no-op since the user is likely the only one
> updating his/her doc at any given time. It's trivial then to have a
> view sorted by #comments as the key and you can get the top-10 that
> way.
>
> K.
>
> On Mon, Oct 5, 2009 at 9:04 PM, Andrew Melo <an...@gmail.com> wrote:
>> you can emit the number of comments as your key, then it will be
>> sorted and you can take the top 10 or whatever.
>>
>> HTH,
>> Andrew
>>
>> --
>> Andrew Melo
>> Andrew.Melo@gmail.com
>>
>>
>>
>> On Mon, Oct 5, 2009 at 8:36 PM, Seggy Umboh <se...@gmail.com> wrote:
>>> Hello everyone,
>>> I've been reading about couchdb and just started playing around with it, and
>>> I am wondering, in the typical blog/comment example application, is it
>>> possible to get a list of the Top 10 commenters? It is trivial to write a
>>> view to get the number of comments for each commenter, but now I want to
>>> sort the result of that view by the values....
>>>
>>
>

Re: Getting a top 10 list by a calculated value

Posted by kowsik <ko...@gmail.com>.
If you have the user and comment as separate docs (with the user_id in
the comment doc), then the simple way is to update the user doc each
time s/he makes a comment with a count of the comments so far.
Conflict resolution is a no-op since the user is likely the only one
updating his/her doc at any given time. It's trivial then to have a
view sorted by #comments as the key and you can get the top-10 that
way.

K.

On Mon, Oct 5, 2009 at 9:04 PM, Andrew Melo <an...@gmail.com> wrote:
> you can emit the number of comments as your key, then it will be
> sorted and you can take the top 10 or whatever.
>
> HTH,
> Andrew
>
> --
> Andrew Melo
> Andrew.Melo@gmail.com
>
>
>
> On Mon, Oct 5, 2009 at 8:36 PM, Seggy Umboh <se...@gmail.com> wrote:
>> Hello everyone,
>> I've been reading about couchdb and just started playing around with it, and
>> I am wondering, in the typical blog/comment example application, is it
>> possible to get a list of the Top 10 commenters? It is trivial to write a
>> view to get the number of comments for each commenter, but now I want to
>> sort the result of that view by the values....
>>
>

Re: Getting a top 10 list by a calculated value

Posted by Andrew Melo <an...@gmail.com>.
you can emit the number of comments as your key, then it will be
sorted and you can take the top 10 or whatever.

HTH,
Andrew

--
Andrew Melo
Andrew.Melo@gmail.com



On Mon, Oct 5, 2009 at 8:36 PM, Seggy Umboh <se...@gmail.com> wrote:
> Hello everyone,
> I've been reading about couchdb and just started playing around with it, and
> I am wondering, in the typical blog/comment example application, is it
> possible to get a list of the Top 10 commenters? It is trivial to write a
> view to get the number of comments for each commenter, but now I want to
> sort the result of that view by the values....
>

Re: Getting a top 10 list by a calculated value

Posted by Zachary Zolton <za...@gmail.com>.
He just described my #1 feature request...

Is this still on the list for 1.0?

On Mon, Oct 5, 2009 at 8:36 PM, Seggy Umboh <se...@gmail.com> wrote:
> Hello everyone,
> I've been reading about couchdb and just started playing around with it, and
> I am wondering, in the typical blog/comment example application, is it
> possible to get a list of the Top 10 commenters? It is trivial to write a
> view to get the number of comments for each commenter, but now I want to
> sort the result of that view by the values....
>