#community-help

Faceting and Filtering Issue in Typesense

TLDR Hauke faced issues with facets filtering in Typesense. Kishore Nallan recommended using the instantsearch.js JS library or the multi_search endpoint for independent search queries.

Powered by Struct AI
12
1mo
Solved
Join the chat
Aug 15, 2023 (1 month ago)
Hauke
Photo of md5-a2785b9d22ba23f3627d4bd877e95e7c
Hauke
10:54 AM
Hello, I'm having an issue with facets and I'm wondering if what I'm looking for is possible:

When filtering by a faceted field, I still want to be able to see the other facet options from this field. Filters from other fields should still apply. So for example:

I have a collection of books with a year and author field. Faceting returns e.g. [2020,2021,2022] for the year. Is there a way to select books from 2020 and still have the other facet options available in the response? When I select 2020 I still want the author facets to be filtered by that query.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
10:56 AM
You're probably looking for this feature? https://github.com/typesense/typesense/issues/943

We've implemented this, and I can share a build with you tomorrow.
Hauke
Photo of md5-a2785b9d22ba23f3627d4bd877e95e7c
Hauke
10:58 AM
Not exactly, the facets are not objects but primitive types. But right now, when I filter by year:2020 the facets in the response only include this year. I want the user to be able to see the other options as well
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:05 AM
Ah got it, something like how it happens in this demo as you apply the facet filters? https://ecommerce-store.typesense.org/
Hauke
Photo of md5-a2785b9d22ba23f3627d4bd877e95e7c
Hauke
11:11 AM
Kishore Nallan yes, that's exactly the behaviour I'm looking for!
11:13
Hauke
11:13 AM
unfortunately my project does not run on node so I'm not sure how to apply this. Is there a special filter flag to achieve this faceting behaviour?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
11:22 AM
We integrate with instantsearch.js JS library which gives you this behavior out of the box. See the demo app uses node, but the requests are made directly from frontend.
11:22
Kishore Nallan
11:22 AM
Otherwise, you will have to use multi_search end-point to make those queries. You can look at the network inspector tab to see the queries being made and figure out what you need to do.
Hauke
Photo of md5-a2785b9d22ba23f3627d4bd877e95e7c
Hauke
12:18 PM
Thank you, I will try that. It seems that I have to make multiple requests for this to work so currently there is no server side feature for this?
12:19
Hauke
12:19 PM
if I use multi_search it will not be multiple requests but still do multiple searches on the typesense server, I presume?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:20 PM
It will go as a single request but inside a multi search request you can have independent search queries
Hauke
Photo of md5-a2785b9d22ba23f3627d4bd877e95e7c
Hauke
12:27 PM
Thanks - I think I know what to do now