Pre-filter on refinementList on load - Instant Search

Hi all,
Version of algolia: instantsearch.js@2.7.1

I am building a project where an object can have multiple tags and building a search for that.

Built the Instant Search as provided in the tutorial with a RefinementList on the right side of the seach based on these Tags.

I would like to be able to preload a page with a specific Tag preselected.
I cannot find the documentation that shows how that would be possible.

For example if I go to http://myurl.com/tag/construction/34554 (construction = tag and 34554 its id).
I would like the tag construction to be preselected in the instant search.

RefinementList code:

search.addWidget(
  instantsearch.widgets.refinementList({
    container: "#categories",
    attributeName: "vertical_names",
    operator: "and",
    searchForFacetValues: true,
    autoHideContainer: false,
    templates: {
      header: "Vertical"
    }
  })
);

Thanks in advance for your help!
Jo

Hi Jo,

If I understand correctly, you have a refinementList and you would like some specific value to be preselected, is that correct ?

You can achieve that by using the searchParameters option like that:

const search = instantsearch({
  appId: //your Algolia appID,
  apiKey: //your algolia search only api Key,
  indexName: //your index name,
  searchParameters: {
   //your search parameters
      disjunctiveFacetsRefinements: {
         attributeName:[values]
     }
    }
  }
});

I have put together a codeSandbox to show an example: https://codesandbox.io/s/0olxjy46wn

You can get the value dynamically from the URL from your own front-end, Algolia doesn’t handle that.

Does this help ?

Best,

Marie