Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 30316 invoked from network); 3 Jul 2008 14:04:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jul 2008 14:04:20 -0000 Received: (qmail 45926 invoked by uid 500); 3 Jul 2008 14:04:21 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 45895 invoked by uid 500); 3 Jul 2008 14:04:21 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 45884 invoked by uid 99); 3 Jul 2008 14:04:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jul 2008 07:04:20 -0700 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [83.97.50.139] (HELO jan.prima.de) (83.97.50.139) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jul 2008 14:03:28 +0000 Received: from [10.0.2.3] (e179134136.adsl.alicedsl.de [::ffff:85.179.134.136]) (AUTH: LOGIN jan, SSL: TLSv1/SSLv3,128bits,AES128-SHA) by jan.prima.de with esmtp; Thu, 03 Jul 2008 14:03:47 +0000 Message-Id: From: Jan Lehnardt To: couchdb-user@incubator.apache.org In-Reply-To: <888cd9180807030652x48c9a680mc65597fb4dce0056@mail.gmail.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v919.2) Subject: Re: Views using JSON Arrays Date: Thu, 3 Jul 2008 16:03:46 +0200 References: <377590.28814.qm@web57215.mail.re3.yahoo.com> <4040EC56-C455-446B-B34F-9B3C9629C593@apache.org> <888cd9180807030652x48c9a680mc65597fb4dce0056@mail.gmail.com> X-Mailer: Apple Mail (2.919.2) X-Virus-Checked: Checked by ClamAV on apache.org To pull that off you'd need to have every single combination of tags in the index which I don't see happening. Maybe with the reduce, I don't know. what you can do is emit([tag1, tag2], null); and then query with key=[tag1, tag2]]; and that would work the octopus and hockey-case you line out here, but not in general. Cheers Jan -- On Jul 3, 2008, at 15:52, Brad King wrote: > Might be a hack, but would a collated view work for getting two > arbitrary tags? > > function (doc) { > for(var i=0; i emit([doc.Tags[i], doc.Tags[i]], null); > > then you pass in ?key=["octopus","hockey"] > > > On Thu, Jul 3, 2008 at 9:15 AM, Jan Lehnardt wrote: >> >> On Jul 3, 2008, at 15:01, Bradford Winfrey wrote: >> >>> Hello everyone, been stalking the mailing list for a while and >>> thought >>> this might be worthy of a post as I was asked to solve it, yet, I >>> couldn't! >>> >>> Let's take the classic blog example document with the following >>> fields/values: >>> >>> "_id": "1f2fc3955b91aed5e7369f0b0ba8214e", >>> "_rev": "1226709986", >>> "Author": "Bradford", >>> "Type": "Post", >>> "Body": "Just mentioning this for a sample blog post.", >>> "PostedDate": "2008-07-02T23:22:12-04:00", >>> "Subject": "My Fine Blog Post", >>> "Tags": ["octopus","hockey","squidward","bradford","recreation"] >>> >>> Next, I'd like to find each blog post that contains ANY of the >>> following >>> tags ["octopus","hockey"]. Now, generally speaking this isn't so >>> bad. We >>> could write a simple view: >>> function (doc) { >>> if (doc.Type == 'Post') { >>> for (var i = 0;i < doc.tags.length; i++) { >>> emit(doc.tags[i],doc); >>> } >>> } >>> } >>> >>> We would get back each one of our tags as a key, yea? Only if we >>> supplied >>> one at a time. So how does one go about supplying a range, array >>> (not sure >>> what we'd call it here) of keys to be searched on? >>> http://...?key=["octopus","hockey"] maybe? I'm unsure of the plan >>> of >>> attack for such a thing. Maybe I'm just going about it in the wrong >>> direction. Any thoughts? >> >> have a look at the bottom of http://wiki.apache.org/couchdb/HttpViewApi >> for the view query options. Specifically the startkey= and endkey= >> ones. >> Note that you only get consecutive ranges with that. To retrieve >> arbitrary >> tags, you'd need to run a query per tag with the key= option. >> >> Cheers >> Jan >> -- >> >