Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 70148 invoked from network); 20 Feb 2011 01:53:23 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Feb 2011 01:53:23 -0000 Received: (qmail 70287 invoked by uid 500); 20 Feb 2011 01:53:21 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 70157 invoked by uid 500); 20 Feb 2011 01:53:21 -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 70149 invoked by uid 99); 20 Feb 2011 01:53:21 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Feb 2011 01:53:21 +0000 X-ASF-Spam-Status: No, hits=2.2 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of gsf747@gmail.com designates 74.125.83.44 as permitted sender) Received: from [74.125.83.44] (HELO mail-gw0-f44.google.com) (74.125.83.44) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Feb 2011 01:53:14 +0000 Received: by gwb20 with SMTP id 20so2342296gwb.31 for ; Sat, 19 Feb 2011 17:52:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type:content-transfer-encoding; bh=AJGYfUBGBROzkj5+/tXw1dk5HjuVjabpRzyU1oKwFBc=; b=xfP9RqXFQ8vyh0iSq5TiAWGofiy5ddQ24mz5Ru8jrm7U4KJ6WFjr0myoQ8+F6ZGBoL lhu7QbhRjNANl2JVuwXMRHeT6pu4+MQbKwQ6CWDxd0p5TjTRxuv4EoToZJLZt2NktDR7 +m2/KSdm2k40KF/K8wCrWuZui6znGhfJfn4M4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=Ja4BQWIME+haDve5HLVksoOzKzx/kglLOZ4j3Hqg1zhd38n6bRuSvYvPjUOQa6OuYH oze1zXtx28PHHKQ8dh2xv6AzZZTO/FUbuQmo3vFdEaX0QxO2NsRezrXs7GxDmvpHDs+q Jkh1PEFe8pa6Ev/mZnjH2gEhe1TOJ9o2bPLy8= Received: by 10.147.125.13 with SMTP id c13mr3754679yan.15.1298166771283; Sat, 19 Feb 2011 17:52:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.146.167.7 with HTTP; Sat, 19 Feb 2011 17:52:31 -0800 (PST) In-Reply-To: References: From: Gabriel Farrell Date: Sat, 19 Feb 2011 20:52:31 -0500 Message-ID: Subject: Re: Query view with multiple keys with OR logic To: user@couchdb.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On Sat, Feb 19, 2011 at 2:54 PM, Simeon F. Willbanks w= rote: > 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 retur= n > 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. Yes, I would run two queries and find the union of the returned IDs in the client. There are some clever ways to do things otherwise but most result in a combinatorial explosion. > 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 = wrote: >> 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 wrot= e: >>> 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 >>> >> >