couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <robert.new...@gmail.com>
Subject Re: date range querying
Date Sun, 06 Feb 2011 22:37:40 GMT
Within couchdb itself, I think you'd have to do as Nils suggested;

for (day = startDate; day < endDate; day= 1 day) {
  emit(day, null);
}

then ?key=<day I want>

Or you could use couchdb-lucene, index startDate and endDate as dates,
query with ?q=startDate:[day TO maxdate]&endDate:[mindate TO day]
where 'date' is the date you are searching for.

B.

On Sun, Feb 6, 2011 at 10:31 PM, Nils Breunese <N.Breunese@vpro.nl> wrote:
> You could emit a view index entry for every day in the date range of a document? This
could become inefficient storage-wise if you have large date ranges.
>
> What exactly "starts returning records that don't match at all"? In what way are you
querying your view? I have to admit I have no idea how I could get the information you're
looking for from that complex key. Also, the emit method takes two arguments AFAIK: a key
and a value. You seem to be emitting a single value?
>
> Nils.
> ________________________________________
> Van: Warner Onstine [warnero@gmail.com]
> Verzonden: zondag 6 februari 2011 22:57
> Aan: user@couchdb.apache.org
> Onderwerp: date range querying
>
> Ok, been banging my head against this for a while and having no luck
> figuring out the logical way to do this (other than installing
> ElasticSearch - which I'll be doing in the near future).
>
> I have records that have startDate and endDate ranges. I want to query
> the view based on today's date. Say I have a record that has a start
> date of 1/31/2011 and an end date of 2/13/2011 and I want to find out
> which records fall within today's date.
>
> In other words
> 1/31/2011 < 2/6/2011 < 2/13/2011
>
> How in the world do I do that? I've been trying something like this:
>       var startDate = new Date(doc.startDate);
>        var endDate = new Date(doc.endDate);
>        var startYear = startDate.getFullYear();
>        var startMonth = startDate.getMonth();
>        var startDay = startDate.getDate();
>        var endYear = endDate.getFullYear();
>        var endMonth = endDate.getMonth();
>        var endDay = endDate.getDate();
>        emit([
>            startYear,
>            startMonth,
>            startDay,
>            endYear,
>            endMonth,
>            endDay
>        ]);
>
> But as soon as I add in the endYear variable it goes wonky and starts
> returning records that don't match at all. Any help is greatly
> appreciated.
>
> -warner
> ------------------------------------------------------------------------
>  VPRO   www.vpro.nl
> ------------------------------------------------------------------------
>

Mime
View raw message