From user-return-20984-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Sun May 27 09:12:58 2012 Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 89F329582 for ; Sun, 27 May 2012 09:12:58 +0000 (UTC) Received: (qmail 81600 invoked by uid 500); 27 May 2012 09:12:57 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 81334 invoked by uid 500); 27 May 2012 09:12:53 -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 81300 invoked by uid 99); 27 May 2012 09:12:52 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 May 2012 09:12:52 +0000 Received: from localhost (HELO mail-ob0-f180.google.com) (127.0.0.1) (smtp-auth username rnewson, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Sun, 27 May 2012 09:12:51 +0000 Received: by obbun3 with SMTP id un3so4874762obb.11 for ; Sun, 27 May 2012 02:12:51 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.173.40 with SMTP id bh8mr2213732igc.65.1338109971072; Sun, 27 May 2012 02:12:51 -0700 (PDT) Received: by 10.42.106.199 with HTTP; Sun, 27 May 2012 02:12:51 -0700 (PDT) In-Reply-To: References: Date: Sun, 27 May 2012 10:12:51 +0100 Message-ID: Subject: Re: how to make queries with logical operators? From: Robert Newson To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi Patrick, Logical OR is straightforward in couchdb views, Martin Higman's answer shows how to do that (though I suggest you don't emit the full doc into your view, emit null as the value instead and use include_docs=3Dtrue). The other suggestions are techniques that would apply if you were attempting a logical AND operator, where you would wish to exclude items that were missing one of two required properties. For that case you would need to do the merge yourself or, more simply and efficiently, use a query engine more powerful than the built-in views (ElasticSearch and couchdb-lucene being two, as previously noted). http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options B. On 27 May 2012 08:24, Martin Higham wrote: > Yes, you need to write a view with a map function ( > http://wiki.apache.org/couchdb/HTTP_view_API) that emits an index of the > doc type. e.g. > > =A0 =A0emit(doc.type, doc) > > and then pass an array of the types you want to retrieve as the keys quer= y > parameter to the view > > For instance if you called the design document mydesign and the view > byType, the http request (before encoding) would be: > > http://localhost:5984/database/_design/mydesign/_view/byType?keys=3D["a",= "b"] > > > On Sunday, 27 May 2012, Patrick Maia wrote: > >> Hi all, imagine I have a database that stores documents like these: >> >> { "type":"a", "attr1":"value1.1", "attr2":"value2.1"} >> { "type":"a", "attr1":"value1.2", "attr2":"value2.2"} >> { "type":"b", "attr3":"value3"} >> { "type":"c", "attr4":"value4"} >> >> Is there some way to get all docs where type =3D=3D "a" or =A0type =3D= =3D "b" doing >> just one http request to couchdb? >> >> Thanks, >> >> Patrick Maia >>