> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Improve results by removing less-important words

> Use query expansion to avoid returning no or few results.

export const Application = () => <Tooltip tip="An Algolia application is a self-contained environment with its own indices, configuration, and API keys. Applications don't share data or settings with each other.">
    application
  </Tooltip>;

export const AlgoliaSearch = () => <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80" width="20" height="20" className="inline" fill="none" role="presentation" ariaLabel="Algolia Search">
    <circle cx="40" cy="32" r="28" fill="#5468FF"></circle>
    <rect x="30" y="22" width="20" height="20" rx="10" fill="#fff"></rect>
    <path d="M43 63.5 54.5 60l6 17h-12L43 63.5Z" fill="#36395A"></path>
  </svg>;

If a query returns no results, Algolia can progressively remove words to broaden the search.
This process is called **query expansion**.

{/* vale Algolia.ProductNames = NO  */}

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.

{/* vale Vale.Spelling = YES  */}

## Query expansion strategies

To support query expansion,
Algolia offers the [`removeWordsIfNoResults`](/doc/api-reference/api-parameters/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](/doc/guides/search-analytics/overview) 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".

| Strategy             | Best when…                                                                                                  | Expansion example                                                                           | Trade-offs                                                           |
| -------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| **`none`** (default) | You only want exact matches.                                                                                | `iPhone 256gb`. Queries are never expanded.                                                 | Can lead to "no results" pages.                                      |
| **`lastWords`**      | Users type the most important terms first.                                                                  | `iphone 5 32gb` → `iphone 5` → `iphone`                                                     | May lose nuance if key information is at the end of the query.       |
| **`firstWords`**     | Users type the most important terms last.                                                                   | `sparkly blue iPhone cases` → `blue iPhone cases` → `iPhone cases` → `cases`                | May lose nuance if key information is at the beginning of the query. |
| **`allOptional`**    | Full 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.                           |

<Note>
  `allOptional` works like the `optionalWords` parameter,
  which is sent at query time.
  For more information,
  see [Creating a list of optional words](/doc/guides/managing-results/optimize-search-results/empty-or-insufficient-results#create-a-list-of-optional-words).
</Note>

## How to apply a query expansion strategy

You can configure the [`removeWordsIfNoResults`](/doc/api-reference/api-parameters/removeWordsIfNoResults) parameter in one of the API clients.

1. Go to the [Algolia dashboard](https://dashboard.algolia.com/explorer/browse) and select your Algolia <Application />.
2. On the left sidebar, select <AlgoliaSearch /> **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](https://dashboard.algolia.com/explorer/browse).

To validate your strategy, consider running an [A/B test](/doc/guides/ab-testing/what-is-ab-testing) with:

* Control (A): set `removeWordsIfNoResults` to `none`.
* Variant (B): set `removeWordsIfNoResults` to use your chosen strategy.

A successful test should show:

* Fewer "no results" in [search analytics](/doc/guides/search-analytics/overview).
* No significant drop in [click and conversion rates](/doc/guides/search-analytics/concepts/metrics).

## 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](/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/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](/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/tokenization#sequence-expressions).

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

* [Search in hyphenated attributes](/doc/guides/managing-results/optimize-search-results/typo-tolerance/how-to/how-to-search-in-hyphenated-attributes)
