#community-help

Typesense Facet Query Issue and Resolution

TLDR Stefan wanted to have typesense return count: 0 for filtered out facets, which was not supported. They shared a workaround using a server data call. The solution involved adding "facets: [this.filterConfig.attribute]," for the server adapter to work. Kishore Nallan acknowledged the resolution.

Powered by Struct AI
8
27mo
Solved
Join the chat
Aug 13, 2021 (27 months ago)
Stefan
Photo of md5-d6c265b4792dbf0a1d6ae378f39d8736
Stefan
01:20 PM
Is there a way to make typesense return count: 0 for facet that are filtered out?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:13 PM
👋 You mean if you apply a filter like brand: foo then the facet count should have foo: 0 as a value?
Stefan
Photo of md5-d6c265b4792dbf0a1d6ae378f39d8736
Stefan
02:21 PM
yes
02:21
Stefan
02:21 PM
but I think it's not possible and not intended
02:22
Stefan
02:22 PM
02:22
Stefan
02:22 PM
If I do what they suggest I get this error when calling the server for initial data

FacetSearchResponseAdapter.js?7637:32 Uncaught (in promise) TypeError: Cannot read property 'counts' of undefined
    at FacetSearchResponseAdapter._adaptFacetHits (FacetSearchResponseAdapter.js?7637:32)
    at FacetSearchResponseAdapter.adapt (FacetSearchResponseAdapter.js?7637:45)
    at eval (TypesenseInstantsearchAdapter.js?7ea0:114)
    at Array.map (<anonymous>)
    at TypesenseInstantsearchAdapter._callee2$ (TypesenseInstantsearchAdapter.js?7ea0:110)
    at tryCatch (runtime.js?96cf:63)
    at Generator.invoke [as _invoke] (runtime.js?96cf:293)
    at Generator.eval [as next] (runtime.js?96cf:118)
    at asyncGeneratorStep (asyncToGenerator.js?c973:3)
    at _next (asyncToGenerator.js?c973:25)
02:30
Stefan
02:30 PM
okay got it working, we have to add "facets: [this.filterConfig.attribute]," in order for the adapter to work
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:32 PM
👍