Instantsearch.js and getSettings

Hi,
I can’t find any example how to use getSettings in instantsearch.js

Thanks

Hi there,

Thank you for your question.

The getSettings method is used more in the backend operation and can’t be used on instantsearch. More information can be found here.

Having said that if you have a specific use case by using the settings in the frontend I may be able to find other alternative solutions.

Please let me know.

Regards,
Harris

Hi.
Thank you for your reply.
I found the follow usage of getSettings in javascript:

index.getSettings(function (err, content) {
        if (content.attributesForFaceting) {
            content.attributesForFaceting.forEach(function (item, index, arr) {
                var productString;

                if (item.indexOf('searchable(') >= 0) {
                    productString = item.slice(item.indexOf('(') + 1, item.indexOf(')'));
                }
                else {
                    productString = item;
                }

                var newDiv = document.createElement('div');
                newDiv.id = index + "-widgetArea";
                document.getElementById("panel-group").appendChild(newDiv);

This example is absolutely my case.
The amount of filter blocks (category, subcategory, brand, and so on) are depends on certain product.
So, I need somehow to show them up.

Thanks.

What you’re looking for is setting facets to * (using configure({ facets: ['*'] })), then you can loop over the response to display all possible facets using the widgets

Thanks for replying.
Could you please give more details?
Maybe a snapshot of the code or the documentation.

slightly different than what I suggested, now that I realise dynamic widgets is released:

search.addWidgets([
  instantsearch.widgets.configure({
    facets: ['*'],
  }),
  instantsearch.widgets.EXPERIMENTAL_dynamicWidgets({
    container: '#facets',
    transformItems(_, { results }) {
      // use the raw results from *
      return Object.keys(results._rawResults[0].facets);
    },
    // list every possible widget once and map
    // also possible to statically list those without mapping
    widgets: [
      'brand',
      'categories',
      'free_shipping',
      'hierarchicalCategories.lvl0',
      'hierarchicalCategories.lvl1',
      'hierarchicalCategories.lvl2',
      'hierarchicalCategories.lvl3',
      'hierarchicalCategories.lvl4',
      'popularity',
      'price',
      'price_range',
      'rating',
      'type',
    ].map((attribute) => (container) =>
      instantsearch.widgets.panel({
        templates: {
          header({ widgetParams: { attribute } = {} } = {}) {
            return attribute;
          },
        },
      })(instantsearch.widgets.refinementList)({ container, attribute })
    ),
  }),
]);

doc for dynamic widgets: dynamicWidgets | InstantSearch.js | API parameters | API Reference | Algolia Documentation