couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anand Chitipothu <anandol...@gmail.com>
Subject Re: how to count the number of unique values
Date Sun, 17 Oct 2010 02:41:22 GMT
2010/10/16 Eli Stevens (Gmail) <wickedgrey@gmail.com>:
> Assuming you have the 'works' docs contain a type and a list of
> subject IDs (code untested, sorry):
>
> map = function(doc) {
>  if (doc.type == 'work') {
>    for (i in doc.subject_ids) {
>        emit(doc.subject_ids[i], [doc._id]); // returning a list of a
> single doc._id makes it so that the reduce function is simpler; it's
> not required though.
>    }
>  }
> }
>
> reduce = function (key, values, rereduce) {
>  var combinedList = [];
>  for (i in values) {
>    combinedList[combinedList.length] = values[i];
>  }
>  return combinedList;
> }
>
> This produces a view with rows like:
>
> {key: 'subj_id1', value: ['work_id1', 'work_id2', ...]},
> {key: 'subj_id2', value: ['work_id2', 'work_id3', ...]},
> {key: 'subj_id3', value: ['work_id1', 'work_id4', ...]},
>
> Does that help?

I thought about this, but in my case the list of can be very big. I've
seen subjects with 500K works. I don't think it is a good idea to let
reduce build such a big list.

Anand

Mime
View raw message