Skip to main content
If a query returns no results, Algolia can progressively remove words to broaden the search. This process is called query expansion. For example, consider an online shop that sells iPhones with 128Β GB and 256Β GB storage. Users searching for iPhone 256gb would see no results. Showing relevant results is better than showing none.

Query expansion strategies

To support query expansion, Algolia offers the removeWordsIfNoResults parameter. It defines how Algolia modifies queries with no results by removing words based on one of four strategies: none (default), lastWords, firstWords, allOptional. Use search analytics to identify typical patterns:
  • Which terms usually appear first in queries.
  • Which terms correlate with clicks or conversions.
  • Which ones most often lead to β€œno results”.
StrategyBest when…Expansion exampleTrade-offs
none (default)You only want exact matches.iPhone 256gb. Queries are never expanded.Can lead to β€œno results” pages.
lastWordsUsers type the most important terms first.iphone 5 32gb β†’ iphone 5 β†’ iphoneMay lose nuance if key information is at the end of the query.
firstWordsUsers type the most important terms last.sparkly blue iPhone cases β†’ blue iPhone cases β†’ iPhone cases β†’ casesMay lose nuance if key information is at the beginning of the query.
allOptionalFull recall, when returning something is better than nothing (useful for blogs and broad product catalogs).blue iPhone cases. Matches any word: blue towels, iPhone repair kits, camera cases.Maximizes recall but sacrifices relevance.
allOptional works like the optionalWords parameter, which is sent at query time. For more information, see Creating a list of optional words.

How to apply a query expansion strategy

You can configure the removeWordsIfNoResults parameter in your API client.
  1. Go to the Algolia dashboard and select your Algolia application.
  2. On the left sidebar, select Search.
  3. Select your Algolia index and open the Configuration tab.
  4. Select Search behavior > No results behavior.
  5. Select your strategy.

Test your query expansion strategy

To check whether the strategy works for your users’ typical search patterns, apply the strategy and test queries in the dashboard. To validate your strategy, consider running an A/B test with:
  • Control (A): set removeWordsIfNoResults to none.
  • Variant (B): set removeWordsIfNoResults to use your chosen strategy.
A successful test should show:

Non-alphanumeric characters

When you change removeWordsIfNoResults from its default none, this can affect how Algolia applies special processing to queries with non-alphanumeric characters:
  • Algolia can treat hyphens and other characters as separators. For example, the query t-shirt may match tshirt and t shirt. For more information, see Splitting and concatenation
  • Algolia enforces the order of words in a query. For example, t-shirt matches t-shirt but not shirt t. For more information, see Tokenization.
These behaviors affect how word removal works. For example, if a user searches for XYZ-b5, you might expect the query to eventually match only XYZ. But because of concatenation and tokenization, it matches XYZ b5 or XYZb5, not only XYZ.

See also

⌘I