Understanding Multisearch in Typesense

TLDR Pantelis needed clarity on multisearch behavior in typesense. Jason explained it's used to get consistent facets for all filters.

Powered by Struct AI
Join the chat
Aug 08, 2023 (1 month ago)
Photo of md5-cf30cea0b09568543ab6a67633468f77
12:12 PM
Hey i have two questions which i think they are related to each other. I have a search query with 3 facets. I am following a custom approach rather than using the typesense adapter and the algolia packages. I have successfully rendered the facets as checkboxes and when i select a facet i managed to send the value in filter_by. For example, filter_by: brand:=['Huawei', 'Apple']. The problem is that the initial query without filters brings back all the facets where the filtered query brings back less facets than the initial. On the contrary, when i inspect the example of the ecommerce store of typesense, i can see that multisearch is used and the search is broken to multiple search queries if a filter is present. Can you explain if there is a particular reason why the multisearch is used and if i must use it in order to bring consistent facets on each filter query? The implementation of the algolia instant search seems to be very abstract to follow.
Photo of md5-8813087cccc512313602b6d9f9ece19f
04:10 PM
Facets are essentially counts of all unique values in given result set.

So if you apply a filter on a particular field and facet on it, it won’t include the other non-filtered values, since it’s not part of the result set.

This is the reason for eg, in the ecommerce demo, the first search in the multi-search request does the query with the filter applied, then it does another query without the filter but with just the facet, to get facet counts for all values