In your Solr index, instead of indexing each business as a single document with a clock, indicate each “retail session” for each business for a week.
For example, if Joe was open Monday to Saturday from 6:00 to 19:00 and closed on Sunday, you would indicate six different documents, each of which had two indexed fields, “open” and “closed”. If your units are 15-minute intervals, then the values can range from 0 to 7 * 24 * 4. Assuming you have a unique identifier for each business, save it in each document so that you can match sessions to enterprises.
Then you can simply do a range search in Solr:
open: [* TO N] And close: [N + 1 TO *]
where N is calculated on the N-th 15-minute interval, which falls the current time. For example, if on Wednesday 10:10 AM, your request would look like this:
open: [* TO 112] And close: [113 TO *]
aka "find a session starting before or before 10:00 a.m. and ending before or after 10:15 a.m."
If you want to include other criteria in your search, such as location or products, you will also need to index this with every session document. This is a bit redundant, but if your index is not huge, this should not be a problem.
Kene
source share