#community-help

Storing Documents with Multi-Category Facets

TLDR Ricardo wanted to know how to store a document with multiple categories as facets. Jason directed to add each category in a string[], and set category as facet: true. Ricardo appreciated Jason's detailed comparisons of Typesense and Algolia and suggested creating a case study.

Powered by Struct AI

1

1

16
31mo
Solved
Join the chat
Apr 30, 2021 (31 months ago)
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
06:31 PM
I'm wondering what's the best way to store a document that has a field category, which I would like it to also be a facet, but the document belongs to multiple categories
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:33 PM
You'd essentially need to pre-join the categories into each document. So every document would have a string[] called categories and you'd add all categories that the record belongs to in that array field
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
06:35 PM
document = {
  'id': '124',
  'title': 'Stark Industries to green energies',
  'category': ['growth', 'tech']
}

06:35
Ricardo
06:35 PM
would a facet filter just on 'tech' return this document?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:36 PM
Yup it will
06:36
Jason
06:36 PM
You'd have to declare category as facet: true in the collection schema
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
06:37 PM
perfect! awesome!

1

06:38
Ricardo
06:38 PM
btw I saw your post on github asking meilisearch guys to change their comparison to typesense.
You should consider making your reply into some sort of document in the documentation or on the website
06:38
Ricardo
06:38 PM
I found it very useful
06:38
Ricardo
06:38 PM
thanks for the help
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:39 PM
Oh ha! It eventually materialized into this table: https://typesense.org/typesense-vs-algolia-vs-elasticsearch-vs-meilisearch/
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
06:39 PM
ah that makes sense ๐Ÿ™‚
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:40 PM
May I know which specific pieces in my response you found useful? I was mainly critiquing their note about Typesense (which they've now removed)...
Ricardo
Photo of md5-914a8b39b82fd99b8ecd985427660deb
Ricardo
06:43 PM
so I liked the default_sorting_field I wasn't even looking at it, and not something that I will use now, but it makes a lot of sense.

"we've heard about teams successfully switching from Algolia to Typesense in production"

"we've deployed 100s of production-grade clusters on Typesense Cloud"

then the showcases although I had looked at those, but didn't notice the size of the datasets before.
06:44
Ricardo
06:44 PM
would be really cool to see a case study (maybe there's one already?) on teams moving from algolia to typesense
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
06:47 PM
Interesting! Good to know. Admittedly we're a little lacking on the marketing front. One user recently voluntarily offered to do a case study for us. May be I'll take them up on it... Time being the main constraint!

1