On Wed, Jun 03, 2009 at 10:54:19PM -0700, Nadav Samet wrote:
> Given a key I'd like to find how many items in a permanent view correspond
> to that key (without retrieving the items themselves, because there can be
> too many).
>
> I currently achieve it by having another mapreduce just to compute this
> count, but it sounds like there must be a better way.
Sounds like the right way to me. If you have an existing view which does
emit(key,anything);
and as long as this view doesn't already have a reduce function, you can add
a counter reduce function(*) to it. Then you just have to remember to query
it with reduce=false when you *don't* want the counts. (I'd prefer it if you
had to say reduce=true to get the reduction, but that's probably just me :-)
Regards,
Brian.
(*) e.g. this one:
function(ks, vs, co) {
if (co) {
return sum(vs);
} else {
return vs.length;
}
}