Guides / Building Search UI / Troubleshooting

InstantSearch.js FAQ

How to use float values in a numeric menu widget?

The numericMenu doesn’t support float values. We recommend storing an integer representation of this value in your records (e.g., 0.5 * 10 = 5) and display the original value in your UI.

How to search from the n-th character?

To search only when the query is longer than a certain length, you can implement a proxy search client. Then, you can add a condition (e.g., query.length > 3).

Why is my uiState ignored?

The uiState only works when the widgets responsible for each UI state attribute are mounted. For instance, a searchBox widget is necessary to provide a query.

Why is my uiState ignored?

The uiState passed to initialUiState or via routing needs to be nested per index. For example, if you only have a root index called “instant_search”, you should use a value like { instant_search: { query: 'query' } }.

How do I change the name of a key in routing?

If you want to change, for example, “query into “q” in routing, you need to use the stateMapping functions to:

  • first, in stateToRoute, return an object containing “q” for the query,
  • then, in routeToState, replace that “q” again with “query”.

Why is search.refresh() not working?

When the search result is the same, some components (templates) may skip re-render.

How can I hide a filter with only one facet value?

You can use a panel widget to access the results, and use the hidden function to hide a refinement based on how many facet values it has:

1
2
3
4
5
6
7
8
9
instantsearch.widgets.panel({
  hidden(options) {
    const facetValues = options.results.getFacetValues('brand');
    return Array.isArray(facetValues) ? facetValues.length <= 1 : false;
  },
})(instantsearch.widgets.refinementList)({
  container: '#brand-list',
  attribute: 'brand',
})

How to search from the n-th character?

To search only when the query is longer than a certain length, you can use the searchFunction to add a condition in which you don’t call helper.search().

Did you find this page helpful?