Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solr date range storing help

How can I store a date-range in solr?

I need to store the start-date and the end-date.

Lets say it is a villa which is for rent during a period (start and end).

I must use two fields right?

In the search the user may chose start-date and end-date, so when querying solr I think I could use something like:

     date:[$start TO $end]

But this only queries one field, which is good but storing the date-range is my problem.

Hmmmmm.

Any help?

Thanks

like image 564
pesar Avatar asked May 13 '26 01:05

pesar


1 Answers

Yes, you'll need two fields.

The query will then have to be on both fields.

Example:

dateFrom:[$start TO $end] AND dateTo:[$start TO $end] 

This would mean that the timespan of the object would have to fall entirely within the timespan you are searching for (e.g. object is 1950-1960 and you search for 1900-2000).

If you just need any part of the object's timespan to fall within the timespan of the search (which in your case seems likely) something like:

dateFrom:[* TO $end] AND dateTo:[$start TO *]

I.e. the object's timespan must begin before the search timespan ends and the object's timespan must end after the search timespan begins. This would find an object from 1900-2000 with a search for 1950-1960.

like image 168
Kris Avatar answered May 15 '26 13:05

Kris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!