Concepts / Managing results / Removing words to improve results
May. 10, 2019

Removing Words to Improve Results

Why Remove Words?

Removing words is the progressive loosening of query constraints to include more results when none are initially found.

For example, imagine an online smartphone shop that sold a limited inventory of iPhones in only 16GB and 32GB varieties. Users searching for “iphone 5 64gb” would see no results. This is not ideal behavior - it would be far better to show users some iPhone 5 results instead of a blank page. That’s where query expansion comes in.

Remove Words If No Results

The removeWordsIfNoResults parameter helps you make an initial query less and less specific until results are found. The right value to choose for a given use case may depend on the language searched as well as usage patterns.

You can choose one of these four behaviors: none (default), lastWords, firstWords, allOptional.

none

This is the engine’s default behavior — no additional processing is done when a query returns no results.

lastWords

This value treats a query’s last word as optional, and if there are still no results, it repeats the operation until either there are results, or the beginning of the query string has been reached.

For example, imagine a search for sparkly blue iPhone cases:

  • The first query is sparkly blue iPhone cases.
  • The second query is sparkly blue iPhone.
  • The third query is sparkly blue.
  • The fourth query is sparkly.

firstWords

This value treats a query’s first word as optional, and repeats the operation until either there are results, or the end of the query string has been reached.

  • The first query is sparkly blue iPhone cases.
  • The second query is blue iPhone cases.
  • The third query is iPhone cases.
  • The fourth query is cases.

It’s important to consider typical search patterns when deciding between firstWords and lastWords. For example, firstWords would be more suitable than lastWords in queries like above. However, this isn’t always the case. For example, let’s take a look at the query “iphone 5 32gb.”

Expanding “iphone 5 32gb” with firstWords

1
"iphone 5 32gb" ➡️ "5 32gb" ➡️ "32gb"

Here, the most relevant part of the query is actually at the front; discarding those words makes the query irrelevant. Compare to the use of lastWords:

Expanding “iphone 5 32gb” with lastWords

1
"iphone 5 32gb" ➡️ "iphone 5" ➡️ "iphone"

This is much better - as we strip away detailed descriptors, we expand our result set without making the query irrelevant.

allOptional

If there are no results for the initial query, allOptional specifies a second search in which all words are treated as optional. This is essentially changing the implicit AND operator between words to OR:

1
"blue AND iPhone AND cases" ➡️ "blue OR iPhone OR cases"

In an e-commerce shop that sold a wide range of products, using allOptional as above would return a far wider range of results - blue towels, books on iPhone development, and camera cases. This breadth would come at the expense of relevance, so it’s best to use this parameter cautiously.

Note: This last option works exactly like optionalWords, which is sent at query time. See discussion here.

Did you find this page helpful?