#community-help

Consolidating Multiple Collection Queries in Typesense

TLDR Cooper asked about consolidating queries from multiple collections, while Jason suggested client-side aggregation. Cooper ended up using nested objects to achieve the desired result.

Powered by Struct AI

1

4
7mo
Solved
Join the chat
Mar 21, 2023 (7 months ago)
Cooper
Photo of md5-b1f0bc2b9d796f6426c0fb73238b7a4d
Cooper
08:17 PM
Hi all 👋

I am looking at using the federated search feature and noticed that the hits when using multiple collections are returned as an array of arrays, one for each index that is being queried. For my application i hope to consolidate querying multiple indices into a single flattened list with correct scoring. Is this a possibility?

The difficulty I'm getting is from using the TypesenseInstantSearchAdapter, where I have to use individual <Index /> components for each collection that I want to query. The example UI from the docs has the returned lists in side-by-side components, whereas I would like a single list (<Hits /> component) with results from both collections, still sorted by score.

I'm new to Typesense and am loving it so far! Very easy to get going with and is really well documented with lots of examples 💃 🙂 Thanks!

1

Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:09 PM
Hi Cooper! Typesense does not have the ability to combine search results from multiple indices into a single result set. I usually tell folks to do this aggregation on the client side (based on the text_match score returned in each result)… however I’m not sure this client-side aggregation is even possible to do with the typesense instantsearch adapter, because when you use the Index widget, it expects results in a certain non-aggregated format…
Cooper
Photo of md5-b1f0bc2b9d796f6426c0fb73238b7a4d
Cooper
09:13 PM
Hi Jason! Thank you for the quick response :)

This makes sense, I think the route I will go is to use nested objects to achieve the same behaviour, and then just using the dot notation to query different object types on a single collection. I tried this and it works nicely via the API.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:14 PM
I see, good to know!