Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 53612 invoked from network); 5 Jul 2009 22:22:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Jul 2009 22:22:28 -0000 Received: (qmail 70313 invoked by uid 500); 5 Jul 2009 22:22:37 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 70225 invoked by uid 500); 5 Jul 2009 22:22:36 -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 70215 invoked by uid 99); 5 Jul 2009 22:22:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jul 2009 22:22:36 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of rbates@gmail.com designates 209.85.210.204 as permitted sender) Received: from [209.85.210.204] (HELO mail-yx0-f204.google.com) (209.85.210.204) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jul 2009 22:22:27 +0000 Received: by yxe42 with SMTP id 42so1894024yxe.13 for ; Sun, 05 Jul 2009 15:22:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=2GrXgWtuYrxEeBurO0mDeqQMaDkfvXv20m9omtWZYHQ=; b=XW93XSK0tcqBeG6nLHUtVTqWTqjtmY1Fg/d0hGtZX3ySKEexb04IPua+DKJovuiPtJ 90tSDpIO6t/bcNWKVeLIvB8z6mNK3mTbFC+/nFQRz6K6ICq287p4LrQABXtcYHh33rOO onmhBJ/xRdccPv9BFb7odgHe+HvKweC3PgSJw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=f/BvArfpgRzkvmZe2IgLcYLR3pyukSpxmCZmtsIhR+iOPCdUdOzLKtcpcvRoKYCMMK lVUbuIEvziwE8TkBf4riOw02Nox5pfw1V50hjEstdJiM/ugaDI8pMBnEC5qoXdv55VLc GVaEiEAEs1J59UmBp3iQtLNl7mQB0Vzw9rwI4= MIME-Version: 1.0 Received: by 10.231.32.69 with SMTP id b5mr1871460ibd.4.1246825113385; Sun, 05 Jul 2009 13:18:33 -0700 (PDT) In-Reply-To: References: <26650b020907041148y17951b4g6b14c0bff5f882f9@mail.gmail.com> Date: Sun, 5 Jul 2009 15:18:33 -0500 Message-ID: <26650b020907051318n7eedd29ehad9decdb2c0240f6@mail.gmail.com> Subject: Re: getting unique set of document id's From: Ross Bates To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=0022152d7c8ffafbf4046dfb1788 X-Virus-Checked: Checked by ClamAV on apache.org --0022152d7c8ffafbf4046dfb1788 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi Paul - thank you for the pointers. Something I'm unclear on though... using a sum in the reduce returns something like this for all the tags: foo, 3 bar, 5 baz, 7 When I use the multi-key fetch against the view it doesn't return specific docid's for each tag, just a subset of tags and their counts. POST {"keys": ["foo", "bar"]} foo, 3 bar, 5 How can I get access to the list of docid's which make up the total? On Sat, Jul 4, 2009 at 3:52 PM, Paul Davis wrote: > On Sat, Jul 4, 2009 at 2:48 PM, Ross Bates wrote: > > Hi All - finally got up an running with 0.9.0 and have been experimenting > > with the POST {"keys": ["key1", "key2", ...]} feature and have a question > > > > Take the typical example of a set of blog posts which can be tagged with > > 1...n tags. Pretend I want to find all posts tagged with both "foo" and > > "bar". > > > > A simple map would look something like this > > > > function(doc) { > > for(i in doc.tags) { > > emit(doc.tags[i], doc._id); > > } > > } > > > > So now when I post {"keys": ["foo", "bar"]} to the view I get all the > > documents tagged "foo", "bar", and also duplicates for any document that > is > > tagged with both. > > > > Is the best option to deduplicate the doc._id on the client and resubmit > to > > all docs, or can this be handled in a reduce function? > > > > Thank you for any help! > > > > Ross > > > > ----- > > @rossbates > > rossbates.com > > > > Assuming the set of tags you want to query isn't known until query > time then you need to go with doing the client side intersection. A > method for making this process a bit faster is to create a view that > lists the tag count using a standard map/reduce of > doc.tags.forEach(function(tag) {emit(tag, 1);}); and a reduce of > "return sum(values)". Then query this view with the multi-key fetch to > get the list of docids for each tag, then query in order of ascending > counts. > > Paul Davis > --0022152d7c8ffafbf4046dfb1788--