Limit Autocomplete To A Collection

Hey, my name’s John, I’m currently doing work on a website where we’d ideally like to have some pages ‘belong’ to a particular brand, related to a collection. We are differentiating this in a few ways but mainly on template suffix.

I’m trying to find a way to only search within the current page’s associated collection. In particular, looking at the autocomplete box. For instance, I don’t want to show a product from another brand as a suggestion if I’m searching from a brand’s About page.

I’m not sure how to go about implementing this and can’t find any documentation for it. I’m open to conditionally including algolia assets/snippets with different values based on the page, or uploading indexes with brand-specific prefixes and changing the prefix value conditionally.

Any guidance you can give me is appeciated.

John

Hi John,

From what I understand, you could use facets: https://www.algolia.com/doc/guides/searching/faceting/#faceting-overview

I’ll add a brand attribute to your records, and then in the autocomplete add a facetFilter based on the brand you want to display.

Could this work for you?

Best,

Hey rcs, that sounds good. For the moment, the most predictable way to get the brand a product is part of is through a tag, would I be able to base my facet off that?

Cheers,

John

It can work with any array based attribute, so a tag will work. I suppose you have records looking like that:

{
  "product_name": "iphone",
  "tags": [
    "phone",
    "smartphone",
    "apple"
  ]
}

So you can add tags as a facet and filter on the facet tags and value apple.