You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

The main documentation for DateRangeField is at Solr's reference guide: https://cwiki.apache.org/confluence/display/solr/Working+with+Dates

Here we're sharing a user-submitted how-to by "Gediminas Zalys"

I would like to share my resolution here for anyone else struggling with this. My requirement was to get all restaurants open now. The caveat was that each restaurant could have multiple opening hours in a single day. And opening hours for each day could vary. Added date_range field into schema.xml:
<field name="openingHours" type="date_range" indexed="true" stored="true" multiValued="true" />
<fieldType name="date_range" class="solr.DateRangeField"/>
Indexed each opening hour for the next week as dates, NOTE! convert your time zones to UTC before indexing openingHours": [
"[2016-02-01T03:00Z TO 2016-02-01T15:00Z]",
"[2016-02-02T03:00Z TO 2016-02-02T15:00Z]",
"[2016-02-03T03:00Z TO 2016-02-03T15:00Z]",
"[2016-02-04T03:00Z TO 2016-02-04T15:00Z]",
"[2016-02-07T03:00Z TO 2016-02-07T15:00Z]",
"[2016-02-05T03:00Z TO 2016-02-05T16:00Z]",
"[2016-02-06T03:00Z TO 2016-02-06T16:00Z]"
],

Now the fun part starts, to get opening hour ranges, which are not dependent on the actual opening hours of any restaurant I passed in the following:
facet.range=openingHours&f.openingHours.facet.range.start=NOW&f.openingHours.facet.range.end=NOW%2B6HOUR&f.openingHours.facet.range.gap=%2B1HOUR facet.range : specifies your facet on which you want to range one f.openingHours.facet.range.start : the time from when the ranges should start - i specified now as i would want to get all restaurants open from now. f.openingHours.facet.range.end : the time when the range should stop, let say i want to range between all restaurants open from now till tonights evening f.openingHours.facet.range.gap : this specifies the gaps in the range (start to end) so if your range is for 12 hours, you can have a gap of 1 Hour, so you will get 12 points in time to range on Now to actually query on these ranges you need to pass the following to fq parameter
{!field f=openingHours op=Contains}[2016-02-02T14:50 TO 2016-02-02T15:00] what the above seas is that you want to query your openingHours to see whether any restaurant is open from 2016-02-02T14:50 TO 2016-02-02T15:00

NOTE : This solution doesn't resolve a problem if you want to see restaurants that are open some time next week as you would only index one week in advance

  • No labels