Our query suggestions feature is designed so that it will only generate suggestions that have results in your index.
However sometimes you might still find that you have some suggestions that do not return results.
The reason for this is that when the query suggestions feature checks for results it does not use any filters, however your site will add filters itself that might mean that less results match than expected (to check that items are in stock for example).
How to solve the problem?
As a first step, you can try making sure that the suggestions have analytics tags matching where the search came from. We have a guide for this here. This should help to reduce the number of suggestions without results.
To fully resolve the issue you will need to create a new query suggestions index that is filtered so that it only contains results that match the filters being applied on your site.
To do this you would want to create a script to generate your filtered index using these steps:
- Create a new Algolia index to store the filtered query suggestions
- Create a script that will browse the query suggestions index to fetch the suggestions
- For each suggestion, run a search using the suggestion and any filters being applied on the site
- If the search finds a result, save the suggestion to the new index. If not, skip it.
- Set the filtered query suggestions as the source to populate the Autocomplete interface.
You would want to run this script regularly (for example once a day) to ensure that its kept up to date.