incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Warner Onstine <warn...@gmail.com>
Subject Re: date range querying
Date Sat, 12 Feb 2011 14:46:40 GMT
I tried that with no success (in fact it completely borked all views
for that document type and had to delete it to get things working
again. I may try and monkey around with these two scripts again to see
what I did wrong.

It really didn't like
day= 1 day

and honestly I'm not even sure what that's supposed to do.

Thanks for the suggestions, I'll let you know if I figure it out. But
I am seriously thinking about using ElasticSearch to make it a more
robust searching solution (I have a lot of searching coming up soon).

-warner

On Sun, Feb 6, 2011 at 3:37 PM, Robert Newson <robert.newson@gmail.com> wrote:
> 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