From user-return-5581-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Tue Jul 21 07:27:08 2009 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 95556 invoked from network); 21 Jul 2009 07:27:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 21 Jul 2009 07:27:08 -0000 Received: (qmail 74787 invoked by uid 500); 21 Jul 2009 07:28:12 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 74743 invoked by uid 500); 21 Jul 2009 07:28:12 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 74733 invoked by uid 99); 21 Jul 2009 07:28:12 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jul 2009 07:28:12 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of b.candler@pobox.com designates 208.72.237.25 as permitted sender) Received: from [208.72.237.25] (HELO sasl.smtp.pobox.com) (208.72.237.25) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Jul 2009 07:28:02 +0000 Received: from localhost.localdomain (unknown [127.0.0.1]) by a-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTP id C3B99E1F9; Tue, 21 Jul 2009 03:27:39 -0400 (EDT) Received: from mappit (unknown [80.45.95.114]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by a-sasl-quonix.sasl.smtp.pobox.com (Postfix) with ESMTPSA id 8FE52E1F8; Tue, 21 Jul 2009 03:27:37 -0400 (EDT) Received: from brian by mappit with local (Exim 4.69) (envelope-from ) id 1MT9lA-0001nM-1w; Tue, 21 Jul 2009 08:27:36 +0100 Date: Tue, 21 Jul 2009 08:27:36 +0100 From: Brian Candler To: Tommy Chheng Cc: user@couchdb.apache.org Subject: Re: multiple key word count query problem Message-ID: <20090721072736.GB6352@uk.tiscali.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-Pobox-Relay-ID: F89925EE-75C7-11DE-A42F-F699A5B33865-28021239!a-sasl-quonix.pobox.com X-Virus-Checked: Checked by ClamAV on apache.org 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.