optionalFilters
'optionalFilters' => [ 'attribute:value', ['attribute1:value', 'attribute2:value'], ]
Can be used in these methods:
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
searchForFacetValues
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
searchAsync,
browseAsync,
searchForFacetValues
Search,
Browse,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
BrowseObjects,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
browse index,
search into facet values,
generateSecuredApiKey,
add key,
update key
About this parameter
Create filters for ranking purposes, where records that match the filter are ranked highest.
Optional filtering behaves like normal filters, meaning that it returns records that match both the query and the filters. However, it also returns records that do not match the filters. The effect is on the ranking: records matching the filters are ranked higher than records that do not match the filters.
Usage notes:
-
The boolean syntax is the same as facetFilters, except for negative syntax. If you use negative syntax, for example
categories:-Book
, it will not work; it will be transformed intocategories:Book
. -
Promoting results: See how you can use
optionalFilters
to promote filters and facets. -
Ranking Formula: This setting will only work if the Filters criterion is part of the ranking. Filters is by default part of the ranking; so if you’ve removed it, and yet wish to use option filters, you’ll need to add it back to the ranking formula.
For customers on the Community, Essential and Plus legacy plans who signed up before December 15, 2018, optional filters are limited to only one per query. Free plans do not have access to optional filters.
For all other plans (Enterprise, Pro, Starter), optional filters are unlimited.
Examples
Apply optional filters on a search query
1
2
3
4
5
6
$results = $index->search('query', [
'optionalFilters' => [
"category:Book",
"author:John Doe"
]
]);