Solr time search within the time range

I know that Solr provides a date field that can store a time instance, and then range requests can be executed to match all documents that have this field in a specific range.

My problem is the opposite. I need to associate several time ranges with documents, and then search for all documents that have search time in one of these ranges.

For example, I index outlets and have 3-4 ranges during which the outlet is open. I need to find all outlets open at a particular point in time.

One way to do this is to specify the start and end time of the duration in the form of separate date fields and compare during the search, for example

(time1_1 > t AND time1_2 < t) OR (time2_1 > t AND time2_2 < t) OR (time3_1 > t AND time3_2 < t)

Is there a better way / faster / cleaner way to do this?

+4
source share
1 answer

Your example looks like the entities of your index are outlet stores, and you save their opening and closing times in separate (possibly dynamic) fields.

If you ask for a different approach, you should consider restructuring an existing scheme or even creating an additional one that uses another object.

This may seem unusual at first, but if this query is the most important for your application, you should consider making the essence of your new index what you want to request: a specific instance of time. I accept it, time - either all day, or half or quarter day.

The scheme should include fields such as an identifier, the start date of a day or half a day, or whatever you choose, an end, and a multi-valued list of identifiers pointing to the exits (stored in your current index (use a multi-core setting)).

Even if you choose a quarter of a day to process the morning, afternoon and night hours separately, and even with a preview of several years, the data should not explode.

This other scheme allows you to:

  • Perform the most important calculations during import so that it is easily accessible when prompted.
  • a simple query that returns in one place what you are looking for

You can even opt out of date fields using your own way of defining ranges. I am thinking of creating an identifier with a date and a string that indicates whether it is morning or afternoon, etc. This will be used as a unique identifier in SOLR. If you can create such an identifier from any requested "temporary instance", you will get a simple search by identifier.

eg. What is open in 2013/03/03 in the morning?

/ Solr / openhours / select q = id: 2013_03_03_am

returns: An array of output ids.

0
source

All Articles