On Sat, Dec 5, 2009 at 8:55 PM, Kamyar Navidan <kamyar.n@gmail.com> wrote:
> Reading through Couchdb: The Definitive Guide I came across this section in
> chapter 06 :
>
> In the blog app, we use group_level reduce queries to compute the count of
>> comments both on a perpost and total basis, achieved by querying the same
>> view index with different methods. With some array keys, and assuming each
>> key has the value 1:
>
>
>> ["a","b","c"]
>
> ["a","b","e"]
>
> ["a","c","m"]
>
> ["b","a","c"]
>
> ["b","a","g"]
>
>
>> The reduce view:
>
>
>> function(keys, values, rereduce) {
>
> return sum(values)
>
> }
>
>
>> returns the total number of rows between the start and end key. So with
>> startkey=["a","b"]&endkey=["b"] (which includes the first 3 of the above
>> keys) the result would equal 3.
>
>
> Earlier in chapter it is stated that:
>
> The startkey and and endkey parameters specify an inclusive range on which
>> we can search.
>
There is an inclusive_endkey=true http query parameter you can use.
>
> So how come the fourth and fifth rows that satisfy endkey=["b"] condition
> are not included in results? I guess I am missing something here. Can
> somebody please clarify this for me.
>
In this case, only the keys:
["a","b","c"]
["a","b","e"]
["a","c","m"]
are included in the range.
the key ["b","a","c"] comes after ["b"] so it is not included. ["b"]
itself would match.
Chris

Chris Anderson
http://jchrisa.net
http://couch.io
