Creating a single list of results from two collections: one large, one small

Hello, I’m working with a team that has two collections: A and B. A has 500,000 documents, while B has 50 documents. When a user submits a query, we want to surface results of both kinds of documents, but we want to show those results in a single set of results. Essentially, we wish to replicate the experience of the Algolia Docs page except in our case, the sizes of the indexes differ by several orders of magnitude.

We’ve tried two approaches to solving this problem, but neither has been ideal so we’re seeking insight from your team as to how to best approach this task.

At first we create two Algolia indices and queried them independently. This ensured we got results from both indices, but it prevented us from determining whether a hit from index B was more relevant to the user’s query than a hit from index A. In this approach, we always rendered hits from index A before hits from index B, because there was no way to compare the hits from the two indices to determine if some of the hits from index B should be rendered before hits from index A.

Our second approach was to create a single index that unified our two collections. However, in this approach, because collection A was so much larger than collection B, our queries essentially only returned documents from collection A and never from collection B.

Is there a good strategy to use in this case? Any tips or suggestions your team can offer would be greatly appreciated.