Preserve searchParameters on clearAll

I have a custom instantsearch widget setup associated with a Shopify store. Because we want some of the auto-generated attributes that come with the Shopify integration, I use the index that the app makes, but since our store includes a lot of duplicates (intentionally for our OMS), I need to filter them out with the following search parameters:

searchParameters: {
    facets: ['variant_title', 'tags'],
    facetsExcludes: {
        variant_title: ['Custom / Custom'],
        tags: ['_hidden']

This works fine, as long as the user doesn’t click “Clear All”. If that happens, the search parameters are also cleared. In general the user should only be able to clear parameters that they set (by selecting facets and queries), but not these pre-set parameters.

Here’s my clear all widget for reference. I just copied it out of the API example, since I thought at the time it would be pretty straightforward:

        container: '#clear-all',
        templates: {
            link: 'Reset everything'
        autoHideContainer: false,
        clearsQuery: true,

Is there a way to preserve these params when a clear-all occurs?

If you are also showing the variant_titles or tags as a facet widget, this is going to be complex.

However, if you’re not, I think you’re looking for the excludeAttributes parameter of the widget : . :slight_smile:
An alternative would be to do this using currentRefinedValues by manually listing all the facets that you want to display and to clear.

Otherwise, you could use the API key solution described in Shopify: Add a filter to the autocomplete and / or the search page to always exclude those results from the search.

Ah ok thanks. We are not using tags for faceting, nor variant_title. I had seen excludeAttributes but for some reason glossed over it I guess. Thanks. I’ll work with that and see if it solves the issue.

1 Like