简体   繁体   中英

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

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 (eg 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 *]

Ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM