问题
All,
I wonder if there is a way can solve this problem that:
I have a lot of solr documents have field pub_date
, but unfortunately with text format like"20180901"
, if I currently want to search by pub_date within a range, how should I achieve it in Solr query?
Thanks,
回答1:
Assuming that all your fields have the same format, i.e. 20180901
- mapping to YYYYMMDD
, you can use a regular range search. The lexiographic ordering of the strings will be the same as for the interval.
pub_date:[20180820 TO 20180901]
will give you any entries between (and including) those two dates. This assumes that there is no other formats used that cause other entries to be inserted in the sort order between those two values.
来源:https://stackoverflow.com/questions/54101425/how-to-search-documents-in-within-date-range-but-based-on-text-format-info-in-so