Load results already filtered in instant search page

Hello, I have some filters on autocomplete in Shopify, but if the users press “Enter”, the search page returns all results, without the filters.
This is what makes autocomplete work:

filters: 'tags = "Tag Name"',

Any suggestions on how to add some filters to be applied by default?

Thank you!

If you want to exclude products from Algolia’s search completely, you can simply use the algolia-ignore tag.

However, if you want to continue with a whitelisting approach for both the autocomplete and the instant search page, you might just want to create an API key as described in this post: Shopify - Hide out of stock product or remove out of stock product from index .

Thanks.
But can’t it work like it does for autocomplete?

Filter with a tag what to stay, not what to hide?

Later Edit: The idea is that I want to filter search based on a cookie. If the cookie is equal to a product tag, only show results with that tag.

Solved.
In algolia_instant_search.js add this line

// Highlight tags
instant.search.addWidget({
  init: function (opts) {
    var helper = opts.helper;
    var page = helper.getPage();
    helper.setQueryParameter('highlightPreTag', '<span class="ais-highlight">');
    helper.setQueryParameter('highlightPostTag', '</span>');
    helper.setQueryParameter('filters', 'tags:"My Tag"'); //add this
    helper.setPage(page);
  }
});

Hi Bogdan,

This is likely to fail as soon as a user selects a facet in the sidebar because filters are managed by the helper which will override it.
However, you can indeed add some custom code to handle this. The main issue is that it will show up in the “Current filters” list at the top, and the best way to avoid this would be to use an API key as recommended in my first message.

instant.search.addWidget({
  // getConfiguration: only needed if you're not already displaying tags in the front-end
  getConfiguration: function () {
    return {
      facets: ['tags']
    };
  },
  init: function (opts) {
    var helper = opts.helper;
    var page = helper.getPage();
    helper.addFacetRefinement('tags', 'My tag');
    helper.setPage(page);
  }
})

@Jerska, thanks a lot!

I’ve hidden facets, just to avoid that :))

But great to know in the future!

Happy to be able to help you!

As a follow-up to this question, I’d now recommend you to look at this post which aggregates information from here and other topics: