removeWordsIfNoResults
'removeWordsIfNoResults' => 'none'|'lastWords'|'firstWords'|'allOptional'
Can be used in these methods:
search,
setSettings,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
set_settings,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
setSettings,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
set_settings,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
setSettings,
browse,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
setSettings,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
SetSettings,
Browse,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
setSettings,
browse,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
SetSettings,
BrowseObjects,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
setSettings,
browse index,
search into facet values,
generateSecuredApiKey,
add key,
update key
About this parameter
Selects a strategy to remove words from the query when it doesn’t match any hits.
The goal is to avoid empty results by progressively loosening the query until hits are matched. You can learn more about this technique, as well as caveats with non-alphanumeric characters, in our in-depth guide on removing words to improve results.
Options
|
No specific processing is done when a query does not return any results (default behavior). |
|
When a query does not return any results, treat the last word as optional. The process is repeated with words N-1, N-2, etc. until there are results, or at most 5 words have been removed. |
|
When a query does not return any results, treat the first word as optional. The process is repeated with words 2, 3, etc. until there are results, or at most 5 words have been removed. |
|
When a query does not return any results, make a second attempt treating all words as optional. This is equivalent to transforming the implicit AND operator applied between query words to an OR. |
Examples
Set default strategy to remove words from the query
1
2
3
4
5
6
$index->setSettings([
'removeWordsIfNoResults' => 'none'
// 'removeWordsIfNoResults' => 'lastWords'
// 'removeWordsIfNoResults' => 'firstWords'
// 'removeWordsIfNoResults' => 'allOptional'
]);
Override default strategy to remove words from the query for the current search
1
2
3
4
5
6
$results = $index->search('query', [
'removeWordsIfNoResults' => 'lastWords'
// 'removeWordsIfNoResults' => 'none'
// 'removeWordsIfNoResults' => 'firstWords'
// 'removeWordsIfNoResults' => 'allOptional'
]);