#community-help

Understanding `facet_by` and `group_by` in Advanced Search

TLDR Emma queried about the function of facet_by and group_by in an advanced search scenario with structured data. Kishore Nallan clarified that facets during group_by are done on the groups.

Powered by Struct AI

1

4
4mo
Solved
Join the chat
Aug 06, 2023 (4 months ago)
Emma
Photo of md5-01ff2c7cb764a071332074d6e85db0c5
Emma
12:34 AM
When I have both facet_by and group_by are the facet counts the number of hits, or the number of groups?
12:44
Emma
12:44 AM
My specific situation is that I’m denormalizing the following structure:
{
  media_id: '123',
  streaming: [
    { site: 'netflix', regions: ['us'] },
    { site: 'netflix', regions: ['ja'] },
    { site: 'hulu', regions: ['us'] }
  ]
}

Into multiple documents like:
{
  media_id: '123',
  streaming: {
    site: 'netflix',
    regions: ['us']
  }
}

So that I can filter by, for example “available on netflix in the united states” like <http://streaming.site:=netflix|streaming.site:=netflix> &amp;&amp; streaming.regions:['us'] in the same object (ie, not matching 'us' in one object and netflix in another, the properties need to match the same object)

I’d like the facets to reflect groups rather than hits, but I have a feeling they don’t

If there’s a better way to achieve this without denormalizing into multiple documents and grouping, please let me know 🙏
12:58
Emma
12:58 AM
Sorry for all the questions btw, advanced search is extremely important to our product and so we’re hitting a lot of these weirdly-specific things as we push against the edges of typesense features 😅 We’re officially past parity with our previous Algolia and Elasticsearch search systems though, so I hope to roll this out soon and then add filters like this and features like vector search!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:10 PM
👋 facets during group_by is done on the groups.

1