- Feature specific data from within your records to, for example, show promotional prices during a sales period
- Display advertisements or promotional banners.
To learn how to suppress InstantSearch’s initial search query, check out the conditional requests guide.
Handling no results
Since not all queries lead to results, it’s essential to let users know when this happens by providing hints on how to adjust the query.Display a message
The easiest way to display a fallback message when a query doesn’t return results is to use thetemplates.empty
option.
All examples in this guide assume you’ve included InstantSearch.js in your web page from a CDN. If, instead, you’re using it with a package manager, adjust how you import InstantSearch.js and its widgets for more information.
JavaScript
The preceding example also works with
infiniteHits
.Let users reset filters and facets
If users apply too many filters, they may not find any results. You should account for this by letting them reset filters from the “no results” display so they can start another search. Do this with theclearRefinements
widget. However, you can’t use it inside the empty
template, so must use routing instead. First, activate the URL sync mechanism:
JavaScript
JavaScript
Handling empty queries
By default, InstantSearch always shows you results, even when the query is empty. Depending on your use case and how you build your UI, you may only want to show results when there’s a query.Using transformItems
UsingtransformItems
to display no results when the query is empty:
JavaScript
Using a connector
The following example uses theconnectHits
connector.
JavaScript
Handling errors
If an error occurs, you can display a specific piece of content to help users return to the standard state.Making an error-handling widget
You can build a custom widget to handle errors. If you want to learn more about custom widgets, check out the guide.JavaScript