ruleContexts
[]
'ruleContexts' => [ 'context_value', ... ]
Can be used in these methods:
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
browse_objects,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
browse,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
browseObjects,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
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
Assigns rule contexts to search queries.
This parameter enables previously created rule contexts. Contexts control whether a rule should apply all the time or only in some situations. For example, contexts can be used to apply rules based on:
- Mobile or desktop device usage
- Landing or :wqproduct category pages
- User interactions—for example, with facets
- Dates, such as promotional periods like Black Friday
- Languages, such as French and English
- Countries, such as Germany and Austria
You can also assign rule contexts with InstantSearch:
Usage notes
- Contexts can only contain alphanumeric characters, hyphens, and underscores.
- If
ruleContexts
is empty, only non-contextual rules are activated. - You can pass up to 10 different contexts to the API at once (at query time).
Examples
Specify rule contexts for the current query
1
2
3
4
5
6
$results = $index->search('query', [
'ruleContexts' => [
'front_end',
'website2'
]
]);