On Sun, Jul 19, 2009 at 08:06:44PM -0700, Tommy Chheng wrote:
> the problem with having two views:
> If i had two views, one for [word, doc] => count and [doc, word] =>  
> count; it would be re-doing the same word counting function twice.

It's usually not a problem, but if it is for some reason (i.e. your view
calculation is especially expensive) then you could do:

  for (var word in wors) {
    emit(["by_word", word, doc._id]);
    emit(["by_id", doc._id, word]);
  }

Then this single view could be queried for e.g.
   startkey=["by_word","the"]&endkey=["by_word","the",{}]
or
   startkey=["by_id","mydoc1"]&endkey=["by_id","mydoc1",{}]

I would expect a single view like this to be a bit larger than two separate
views, because of the extra tags being stored.

Reply via email to