Search for objects in time range using multiple time ranges

I have read the documentation & other discussions exhaustively and cannot find a solution to this issue. Any help is wholly welcomed here!


I would like to search for objects which contain a time range that overlaps with at least some time ranges in an array of time ranges being search for.

consider the following data-structure stored on algolia:

{
id: num
timeRanges: [
     { 
       start: 1691478000, // Tue Aug 08 2023 07:00:00 GMT
       end: 1691485200	// Tue Aug 08 2023 09:00:00 GMT
     }
     ...
  ]
}

And consider you are trying to find out if any object on Algolia has a time range that matches at least one time range in an array of time ranges:

const searchForObjectsContaining = [
    {start: number, end: number},
    {start: number, end: number},
    {start: number, end: number},
    ...
]

This obvious approach would be to write a filter query this like:

{
    filter: `
      // for each timeRange in searchForObjectsContaining:
      (
        NOT timeRanges.start < ${startOfDay(timeRange.start)}
          AND
        NOT timeRanges.end > ${endOfDay(timeRange.end)}
          AND
        timeRanges.start <= ${timeRange.start}
          AND
        timeRanges.end >= ${timeRange.end}
      )
      OR
      (
        ${/* insert other time ranges to query for... */}
      )
      ...
    `
}

Obviously as the docs explain Algolia doesn’t allow for nested AND operators which makes this type of approach impossible.

So I need some other type of workaround that I just can’t figure out.

I have tried doing this type of query post-search on my own server but as the complexity of the post-search filtering is cubic (num of search hits * num of hits.timeRanges * num of timeRanges to query for), it’s a pretty terrible solution.

I have also tried negating the boolean logic in the filters, but this doesn’t seem to work either because multiple boolean conditions are still needed per timeRange… so you still need a nested AND operator.

I have also tried using numericFilters but I see that they too don’t allow nested AND operators…

If there is anything else that can be recommended, I would very much welcome the support!