Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 52835 invoked from network); 19 Feb 2011 19:54:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Feb 2011 19:54:36 -0000 Received: (qmail 7388 invoked by uid 500); 19 Feb 2011 19:54:35 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 7300 invoked by uid 500); 19 Feb 2011 19:54:34 -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 7291 invoked by uid 99); 19 Feb 2011 19:54:34 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Feb 2011 19:54:34 +0000 X-ASF-Spam-Status: No, hits=0.3 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_SOFTFAIL X-Spam-Check-By: apache.org Received-SPF: softfail (nike.apache.org: transitioning domain of simeon@simeons.net does not designate 209.85.215.52 as permitted sender) Received: from [209.85.215.52] (HELO mail-ew0-f52.google.com) (209.85.215.52) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 19 Feb 2011 19:54:27 +0000 Received: by ewy10 with SMTP id 10so133797ewy.11 for ; Sat, 19 Feb 2011 11:54:06 -0800 (PST) MIME-Version: 1.0 Received: by 10.14.37.7 with SMTP id x7mr2428835eea.48.1298145244754; Sat, 19 Feb 2011 11:54:04 -0800 (PST) Received: by 10.14.29.11 with HTTP; Sat, 19 Feb 2011 11:54:04 -0800 (PST) In-Reply-To: References: Date: Sat, 19 Feb 2011 11:54:04 -0800 Message-ID: Subject: Re: Query view with multiple keys with OR logic From: "Simeon F. Willbanks" To: user@couchdb.apache.org Cc: Robert Newson Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Correct. In retrospect, I am looking for an idiom or preferred way to achieve a dynamic view. My example states I'd like to query by type=3D"post" OR tag=3D"tag1", but I'd like the key values to be dynamic. My next request might be type=3D"photo" OR tag=3D"tag2". This would return IDs 1, 2 and 3. I understand temporary views are an option, but they aren't efficient. Would it be best to have two permanent views which can be queried by key and merge the results in the client? I could have one permanent view by_type and another by_tag. This technique looks to be described in the blog post below, but its from 2009. http://sitr.us/2009/06/30/database-queries-the-couchdb-way.html Thanks, Simeon On Sat, Feb 19, 2011 at 9:49 AM, Robert Newson wr= ote: > While this; > > function(doc) { > =C2=A0if (doc.type=3D=3D"post") { > =C2=A0 =C2=A0emit(null, null); > =C2=A0} > =C2=A0for (var i=3D0; i =C2=A0 =C2=A0if (doc.tags[i] =3D=3D "tag1") { > =C2=A0 =C2=A0 =C2=A0emit(null, null); > =C2=A0 =C2=A0} > =C2=A0} > } > > achieves your stated goal, I don't think it's what you're really > asking for, right? > > B. > > On 19 February 2011 16:17, Simeon F. Willbanks wrote= : >> Hello, >> >> I'm trying to fetch a set of documents with OR logic. For example, >> fetch all documents with type=3D"post" OR tag=3D"tag1". Here are a few >> example documents with rev omitted for brevity: >> >> { >> =C2=A0 =C2=A0"_id": 1, >> =C2=A0 =C2=A0"type": "post", >> =C2=A0 =C2=A0"tags": [ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0"tag1", >> =C2=A0 =C2=A0 =C2=A0 =C2=A0"tag2" >> =C2=A0 =C2=A0] >> } >> >> { >> =C2=A0 =C2=A0"_id": 2, >> =C2=A0 =C2=A0"type": "photo", >> =C2=A0 =C2=A0"tags": [ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0"tag1", >> =C2=A0 =C2=A0 =C2=A0 =C2=A0"tag3" >> =C2=A0 =C2=A0] >> } >> >> { >> =C2=A0 =C2=A0"_id": 3, >> =C2=A0 =C2=A0"type": "photo", >> =C2=A0 =C2=A0"tags": [ >> =C2=A0 =C2=A0 =C2=A0 =C2=A0"tag4", >> =C2=A0 =C2=A0 =C2=A0 =C2=A0"tag5" >> =C2=A0 =C2=A0] >> } >> >> I'd like to fetch documents with the ids 1 and 2. >> >> It seems this method will be my starting point: >> "A JSON structure of {"keys": ["key1", "key2", ...]} can be posted to >> any user defined view or _all_docs to retrieve just the view rows >> matching that set of keys. Rows are returned in the order of the keys >> specified. Combining this feature with include_docs=3Dtrue results in >> the so-called multi-document-fetch feature." >> http://wiki.apache.org/couchdb/HTTP_view_API >> >> Am I correct so far? If yes, how would I define my map function? Would >> I call emit multiple times and possibly use a group=3Dtrue parameter? >> >> Thanks, >> Simeon >> >