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 $e开发者_如何学JAVAnd]
But this only queries one field, which is good but storing the date-range is my problem.
Hmmmmm.
Any help?
Thanks
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.
精彩评论