You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Mathieu Castonguay <mc...@justlexit.com> on 2012/04/23 20:27:36 UTC

question about ranges

I have a very simple model with a list of lists of integers, ie
[[11000,20000],[23000,40000],[61400,62200],[71400,72200]]

I have a view which loops through these and emits them

"test6": {
           "map": "function(doc) { if (doc.ranges) { for (var x in
doc.ranges) { emit(doc.ranges[x], doc._id) }}}"
       },



and then I basically want to pull the ones that are within my range:

test6?startkey=[52000,0]&endkey=[74000,64000]

this returns:

{"total_rows":7,"offset":5,"rows":[
{"id":"059a2e3b15364dcdfe412a6998021832","key":[61400,62200],"value":"059a2e3b15364dcdfe412a6998021832"},
{"id":"059a2e3b15364dcdfe412a6998021832","key":[71400,72200],"value":"059a2e3b15364dcdfe412a6998021832"}
]}


But what I was expecting is to only see the [61400,62200] because i thought
that with this query I was doing [Between(52000,74000),Between(0,64000)]

There's obviously something wrong with my logic, can someone lend a hand?

Re: question about ranges

Posted by Simon Metson <si...@googlemail.com>.
Hey, 
I tried to explain this in https://drsm79.cloudant.com/view-slicing/_design/view-slicing/index.html
Cheers
Simon


On Monday, 23 April 2012 at 21:28, Mark Hahn wrote:

> thx,
> 
> i'll put them in right now -- i will also set a reminder on my calendar so
> you don't have to bug me.
> 
> On Mon, Apr 23, 2012 at 1:12 PM, Robert Newson <rnewson@apache.org (mailto:rnewson@apache.org)> wrote:
> 
> > Correct, couchdb cannot do a join (aka AND). You could try
> > couchdb-lucene, though.
> > 
> > B.
> > 
> > On 23 April 2012 19:45, Matthieu Rakotojaona
> > <matthieu.rakotojaona@gmail.com (mailto:matthieu.rakotojaona@gmail.com)> wrote:
> > > Your problem is a 2D problem. What you might need is something like
> > > geocouch [0], or you could try chained map/reduce views.
> > > 
> > > [0] https://github.com/couchbase/geocouch
> > > 
> > > --
> > > Matthieu RAKOTOJAONA
> > > 
> > 
> > 
> 
> 
> 



Re: question about ranges

Posted by Mark Hahn <ma...@hahnca.com>.
thx,

i'll put them in right now -- i will also set a reminder on my calendar so
you don't have to bug me.

On Mon, Apr 23, 2012 at 1:12 PM, Robert Newson <rn...@apache.org> wrote:

> Correct, couchdb cannot do a join (aka AND). You could try
> couchdb-lucene, though.
>
> B.
>
> On 23 April 2012 19:45, Matthieu Rakotojaona
> <ma...@gmail.com> wrote:
> > Your problem is a 2D problem. What you might need is something like
> > geocouch [0], or you could try chained map/reduce views.
> >
> > [0] https://github.com/couchbase/geocouch
> >
> > --
> > Matthieu RAKOTOJAONA
>

Re: question about ranges

Posted by Robert Newson <rn...@apache.org>.
Correct, couchdb cannot do a join (aka AND). You could try
couchdb-lucene, though.

B.

On 23 April 2012 19:45, Matthieu Rakotojaona
<ma...@gmail.com> wrote:
> Your problem is a 2D problem. What you might need is something like
> geocouch [0], or you could try chained map/reduce views.
>
> [0] https://github.com/couchbase/geocouch
>
> --
> Matthieu RAKOTOJAONA

Re: question about ranges

Posted by Matthieu Rakotojaona <ma...@gmail.com>.
Your problem is a 2D problem. What you might need is something like
geocouch [0], or you could try chained map/reduce views.

[0] https://github.com/couchbase/geocouch

-- 
Matthieu RAKOTOJAONA

Re: question about ranges

Posted by Mathieu Castonguay <mc...@justlexit.com>.
Ok I understand.

So how you would you do two checks then, as far as I know there is no
equivalent of "AND" and the only way to do this is to do two seperate
queries and then join the results (ie do my first range and then second
range and combine the results).

Is there a way to do this in a single query?

On Mon, Apr 23, 2012 at 2:31 PM, Robert Newson <rn...@apache.org> wrote:

> Sure. CouchDB views are one dimensional, sorted by the full key. Your
> query will return all rows with a key equal to or greater than
> [52000,0] and less than [74000,64000]. This includes [71400,72200] as
> 71400 is greater than 52000 and less than 74000.
>
> http://wiki.apache.org/couchdb/View_collation
>
> B.
>
> On 23 April 2012 19:27, Mathieu Castonguay <mc...@justlexit.com>
> wrote:
> > I have a very simple model with a list of lists of integers, ie
> > [[11000,20000],[23000,40000],[61400,62200],[71400,72200]]
> >
> > I have a view which loops through these and emits them
> >
> > "test6": {
> >           "map": "function(doc) { if (doc.ranges) { for (var x in
> > doc.ranges) { emit(doc.ranges[x], doc._id) }}}"
> >       },
> >
> >
> >
> > and then I basically want to pull the ones that are within my range:
> >
> > test6?startkey=[52000,0]&endkey=[74000,64000]
> >
> > this returns:
> >
> > {"total_rows":7,"offset":5,"rows":[
> >
> {"id":"059a2e3b15364dcdfe412a6998021832","key":[61400,62200],"value":"059a2e3b15364dcdfe412a6998021832"},
> >
> {"id":"059a2e3b15364dcdfe412a6998021832","key":[71400,72200],"value":"059a2e3b15364dcdfe412a6998021832"}
> > ]}
> >
> >
> > But what I was expecting is to only see the [61400,62200] because i
> thought
> > that with this query I was doing [Between(52000,74000),Between(0,64000)]
> >
> > There's obviously something wrong with my logic, can someone lend a hand?
>

Re: question about ranges

Posted by Robert Newson <rn...@apache.org>.
Sure. CouchDB views are one dimensional, sorted by the full key. Your
query will return all rows with a key equal to or greater than
[52000,0] and less than [74000,64000]. This includes [71400,72200] as
71400 is greater than 52000 and less than 74000.

http://wiki.apache.org/couchdb/View_collation

B.

On 23 April 2012 19:27, Mathieu Castonguay <mc...@justlexit.com> wrote:
> I have a very simple model with a list of lists of integers, ie
> [[11000,20000],[23000,40000],[61400,62200],[71400,72200]]
>
> I have a view which loops through these and emits them
>
> "test6": {
>           "map": "function(doc) { if (doc.ranges) { for (var x in
> doc.ranges) { emit(doc.ranges[x], doc._id) }}}"
>       },
>
>
>
> and then I basically want to pull the ones that are within my range:
>
> test6?startkey=[52000,0]&endkey=[74000,64000]
>
> this returns:
>
> {"total_rows":7,"offset":5,"rows":[
> {"id":"059a2e3b15364dcdfe412a6998021832","key":[61400,62200],"value":"059a2e3b15364dcdfe412a6998021832"},
> {"id":"059a2e3b15364dcdfe412a6998021832","key":[71400,72200],"value":"059a2e3b15364dcdfe412a6998021832"}
> ]}
>
>
> But what I was expecting is to only see the [61400,62200] because i thought
> that with this query I was doing [Between(52000,74000),Between(0,64000)]
>
> There's obviously something wrong with my logic, can someone lend a hand?