couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Klo <>
Subject Re: Need some advice
Date Fri, 27 Apr 2012 22:02:26 GMT
Okay, sorry, I missed the following days part. I'm not sure you can do exactly what you want
with a view only, but you probably want a list function as well. the GeoCouch plugin would
have been your best bet for that... too bad... 

You can still use the same type of view with keys like: [ date, eventid ], then create a list
function that uniques the eventid's; just do this any time the eventid changes in the 'stream'
you send the details once, - and if you include with_docs; you could add the event details
you want as well. 

I do something very similar to this here:

Alternatively which is probably simpler:

If you can place  some kind maximum fixed range requirement that's reasonable, like I always
want to show events within 5 days of the each event...  you could artificially emit extra
date keys in your map...  5 days before and 5 days after the event...

Say your event is for May 5, then you emit that event for every day in the map from Apr 30
- May 10.  You might have another event on the May 2, which you emit dates from April 27 -
May 7.  If I search for May 2, event.. i'll also get the may 5 event.

Then when you query the view with a simple reduce for a specific day... you should get a list
of all events within 5 days (10 day range)... of the date specified.  If you put some kind
of larger limit on that like 14 days before and after.. then post filter the result set using
a list function into a smaller range, to dates before or after, and etc.

- Jim

Jim Klo
Senior Software Engineer
Center for Software Engineering
SRI International

On Apr 27, 2012, at 2:06 PM, Stephan Bardubitzki wrote:

> Thanks for your suggestions Jim.
> Unfortunately, I have to count out GeoCouch for now and your first suggestion doesn't
satisfy my requirements. It would yield the events for a particular day, but not for all following
days, requiring more connections to the db which I want to avoid for a mobile app.
> Before posting I have tried a couple days to find a clean solution, but came up with
the start_date as key. It gives me all events, including past events, and the hard work has
to be done on client side.
> My finding works, just have the feeling there is a more efficient way.
> Stephan
> On 12-04-27 11:38 AM, Jim Klo wrote:
>> There's a whole bunch of ways to do that... but here are 2:
>> 1. create a map function that emits all the days of the event as keys - the searching
for any particular day would yield those events
>> 2. use geocouch, store the start & end dates as a box, then you can use the current
date as a bbox to find all events that overlap. Using this method, you'd want to store time
as an integer value and not a string.
>> IMHO #2 is probably a cleaner approach, but requires GeoCouch.
>> - Jim
>> *
>> *
>> *
>> *Jim Klo*
>> Senior Software Engineer
>> Center for Software Engineering
>> SRI International
>> *
>> *
>> *
>> On Apr 27, 2012, at 11:19 AM, Stephan Bardubitzki wrote:
>>> I have a database of events and since events can be multi-day events all documents
have a start_date and end_date. Now I want to get all events that happen today and those that
are starting in the coming days.
>>> How should I determine if today is in the range of start_date and end_date?
>>> To make things more complex an event can be assigned to one or more categories
such as sports, music etc. So the next task would be to get all events of a certain category
that happen today and in the coming days.
>>> Since a db of events might be a common task I hope someone has already come up
with a solution.
>>> Any advice would be greatly appreciated.
>>> Stephan

View raw message