couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Glenn Rempe <gl...@rempe.us>
Subject Re: Help with complex key range query and map/reduce
Date Tue, 29 Sep 2009 20:00:18 GMT
Thanks Jesse for helping me walk through this.  I think I am (slowly)
wrapping my head around it. :-)  I think your example of having two
different views to cover this is helpful.  Let me replay, and tell me if I
may finally have it.

(Just a note to clarify my use case, the date ranges can be an arbitrary
number of days e.g. Today - 60 days, and not strictly tied to one month at a
time on the natural monthly boundaries).

    # Break up the views by *either* ALL engines, or a *SPECIFIC* engines.
 A different view for each. The view executed is based on whether the engine
is all or specific.

    # View 1 : When you want to query a single category (1), ALL engines,
and a date range of 8/1 - 9/30:
    #   [1,2009,8,1] to [1,2009,9,30]

    # View 2 : When you want to query a single category (1), a SPECIFIC
Engine, and a date range of 8/1 - 9/30:
    #   [1,"g", 2009,9,1] to [1,"g",2009,9,30]

Correct?

Thanks again.  Hopefully I've got it now.

Glenn

On Tue, Sep 29, 2009 at 9:17 AM, Jesse Hallett <hallettj@gmail.com> wrote:

> Glenn,
>
> I am afraid that to do what you want to do you will need at least two
> different views.  As Ning explained, the most significant position of the
> key determines what will be filtered.  For example:
>
>    start: [1, 2009, 9, 1, "g"]
>    end:  [1, 2009, 9, 29, "g"]
>
> Will return all results for September with cat_id 1, regardless of engine,
> except that it will exclude items from 9/1 with engines "a"-"f" and items
> from 9/29 with engines "h"-"z".  To demonstrate this, consider these
> ordering facts:
>
>    [1, 2009, 9, 5, "r"] > [1, 2009, 9, 1, "g"]  // 5 > 1
>    [1, 2009, 9, 23, "m"] < [1, 2009, 9, 29, "g"]  // 23 < 29
>
> That is why it is necessary to move the engine parameter in front of the
> date.  If you want the options of filtering by a specific engine or
> including all engines in a given date range you will need two different
> views that have keys that are ordered differently.  If you want a specific
> range of engines you will have to lock that query to a specific date
> parameter.  But you can for example create a view that only emits year and
> month values for the date to query based on a specific range of engines
> over
> one month.
>
>

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