Combining results from two or more queries of the same index?

Hi all! I’m here with a question that is related to a few others that have been asked here, but I was not really able to find a solution to my specific use-case.

My team and I are attempting to filter results from a single index, however, our ideal filtering uses one or more disjunctions of conjunctions (ORs of ANDs), which is prohibited as per Algolia’s docs.

Our initial workaround here was to query the same index multiple times for each set of conjunctions and combine the results into a single Hits and Pagination UI, yet we cannot figure out a way to do this. We attempted to use the useAutocomplete hook to get the indices data and get the Hits from there, but those results return a single page for each query, and we want to combine all the hits from the various filtered queries and paginate them together.

Here’s an example of the kind of filtering we are attempting to perform on our index:

Say our Index contains flight data such as

[
    {
        airline,
        departureTime,
        ...moreFlightDetails
    },
    ...moreFlights
]

and want to create a filter like

(airline:A AND departureTime:6 TO 10) OR (airline:B AND departureTime:12 TO 16)

is there an algolia way to surface these results in an aggregated list with pagination?

Thanks!

As you mentioned, we do not allow the combination of ANDs and ORs you require for performance reasons.

We limit filter expressions to a conjunction (ANDs) of disjunctions (ORs). For example you can use filter1 AND (filter2 OR filter3) ), but not ORs of ANDs (e.g. filter1 OR (filter2 AND filter3)

The type of query you need does not perform well with the way Algolia indexes your data. We’re better suited to “all flights from this set of airlines between these departure times”. Specifying individual time frames per airline may ned a SQL query or API call (perhaps graphQL).