Volt
Volt

Reputation: 71

instantsearch.js: filter initial search with query parameter from Algolia

I've been trying to filter the initial search with this query parameter from Algolia with no success. What I've read in the docs is you have to add the query parameter and a query string but so far it do the job.

This is the code I've been working with

var search = instantsearch({
  appId: 'API ID',
  apiKey: 'APY KEY SEARCH',
  indexName: 'per_posts_product',
   searchParameters: {
        facets: ['taxonomies.product_cat'],
        facetsRefinements: {'taxonomies.product_cat': 'Dual Daggers'}
    },
  routing: true
});

Upvotes: 2

Views: 1856

Answers (1)

Samuel Vaillant
Samuel Vaillant

Reputation: 3847

The values provided to the facetsRefinements should be an array not a string. Here is an example that shows how to use it:

const search = instantsearch({
  appId: 'APP_ID',
  apiKey: 'API_KEY',
  indexName: 'INDEX_NAME',
  searchParameters: {
    facets: ['taxonomies.product_cat'],
    facetsRefinements: {
      'taxonomies.product_cat': ['Dual Daggers'],
    },
  },
});

Don't forget to declare your attribute as attributesForFaceting inside your index.

Upvotes: 2

Related Questions