#community-help

Facet Searching and Filtering in Typesense

TLDR David asked about how to perform a facet search and filter specific categories in documents. Kishore Nallan guided them on how to accomplish it and also mentioned curation based on filter_by is available in recent RC builds. This solution was also confirmed by Jason.

Powered by Struct AI
+11
star-struck1
12
11mo
Solved
Join the chat
Oct 19, 2022 (11 months ago)
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
08:16 AM
How do I preform a facet search for all documents against a type like this?
{
  "facet": true,
  "index": true,
  "infix": false,
  "locale": "",
  "name": "categories.lvl0",
  "optional": false,
  "sort": false,
  "type": "string[]"
}
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
08:46 AM
You should be able to facet by just sending "facet_by": "categories.lvl0" as a search param. What problem are you facing?
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
08:59 AM
Kishore Nallan That's for responding 🙂 I want all the documents where lvl0 is Furniture { "categories.lvl0": ["Furniture"] } for example, or all the documents where lvl1 is Sofas, like { "categories.lvl0": ["Furniture"], "categories.lvl1": ["Sofas", "Poufs"] }
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:00 AM
That's filtering and you can do that via filter_by , e.g. filter_by=categories.lvl0:= Furniture
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
09:02 AM
Ok, thanks! Side-question: Do you recommend the whole { "categories.lvl0": ["Furniture"], "categories.lvl1": ["Furniture > Sofas", "Furniture > Poufs"] } dance where you add the parent and a seperator into the lvls? I know Algolia recommends that
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:07 AM
I think our examples also follow the same pattern, tagging Jason who can maybe suggest if there's a better way here.
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
01:05 PM
Another related question 🤔 Kishore Nallan Jason I'm now using this query q=*&filter_by=categories.lvl1:= Furniture > Shelving and storage&per_page=32 for a category page, and it works great. But how does the curation work here? From what I can tell curation is only for the query (* in this case) and not for the filter? If i want to move item id 123 to the top of the Furniture > Shelving and storage page and document id 456 to the top of the Furniture > Tables and side tables page, how do I do that?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:07 PM
Curation based on filter_by rules is available on recent RC builds. See: https://github.com/typesense/typesense/issues/536#issuecomment-1238746446
David
Photo of md5-07c4f1bfa85fc4a2759ba7302f0b86da
David
01:09 PM
Since it is on a RC build, it's not available through the Typesense Cloud UI then?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:14 PM
We can upgrade from our end, you can schedule an upgrade from the UI.
star-struck1
01:14
Kishore Nallan
01:14 PM
Or you can also email us if there is no specific time where the upgrade should happen.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:21 PM
> https://typesense-community.slack.com/archives/C01P749MET0/p1666170133558749?thread_ts=1666167377.380949&cid=C01P749MET0
If you’re using Instantsearch, then this is the format that those widgets work with
+11