tags:

views:

84

answers:

1

Hi, I'm trying to come up with a way to query dates in Lucene. Basically I have an event that has a start date, end date and can also occur regularly. The way I tried to go about it was to create an index field in Lucene that would list all the possible dates separated by a comma (or empty space would be enough, really) and than apply range search to it. The dates were indexed like this:

Event A starting on 31-10-09: "20091031"

Event B starting on 31-10-09 and lasting for 2 days: "20091031, 20091101, 20091102"

Event C recurring every Saturday for next 3 Saturdays: "20091031, 20091107, 20091114"

That however didn't work because if I was looking for events between 20091030 and 20091101, it should list events A, B and C but because B and C had some occurrences outside of the required range it did not find them.

Any idea how to solve it? Thanks

+1  A: 

A possible way to do this is to create a separate document per each occurrence of every event. Both event B and C will then have three documents each, each of them having a date field and an event name field. A simple range search could then find the events.

A separate question is whether to do this in Lucene at all. Please see Search Engine versus DBMS for a discussion of related issues.

Yuval F
That's actually a good idea. Thanks! As for the Lucene/DBMS decision, it is too late for this kind of decision at this stage of the project. However my search algorithm is more complicated than just range search and even though I'm sure I could implement weighting of different attributes etc. in RDBMS, it just seems like too much of a hassle.
Ondrej Stastny