couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Patrick Maia <patrickjourdanm...@gmail.com>
Subject Re: how to make queries with logical operators?
Date Sun, 27 May 2012 15:51:01 GMT
In my scenario, I actually need a logical AND operator, where I would wish
to exclude items that were missing one of two required properties.
For example: I want to get all docs where (country == "Brasil" AND
state=="Paraíba" AND city=="João Pessoa" AND time > 1338133249 AND time <
1369669248) AND (type == 1 OR type == 3)

In this case, if I choose to do the merge myself, it would be something
like this:

1. create a view that emits ([doc.country, doc.state, doc.city, doc.time],
null)
2. create another view that emits (doc.type, null)
3. query view 1 passing startkey=["Brasil","Paraíba","João
Pessoa",1338133249]&endkey=["Brasil","Paraíba","João Pessoa",1369669248]
4. query view 2 passing keys=[1,3]
5. calculate the intersection of both sets

Right? How can I efficiently implement pagination in a scenario like this?
ElasticSearch and/or couchdb-lucene makes it easier?

Thanks a lot,

Patrick Maia


On Sun, May 27, 2012 at 6:12 AM, Robert Newson <rnewson@apache.org> wrote:

> 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=true).
>
> 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 <martin@ocasta.co.uk> 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.
> >
> >    emit(doc.type, doc)
> >
> > and then pass an array of the types you want to retrieve as the keys
> query
> > 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=[
> "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 == "a" or  type == "b"
> doing
> >> just one http request to couchdb?
> >>
> >> Thanks,
> >>
> >> Patrick Maia
> >>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message