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 the listed Rule contexts at query time. However, you must first create your Rule contexts from the dashboard or with the save-rule
method
A context controls whether a Rule should apply all the time or only in some situations. Common applications of context are when you want to apply Rules based on the following scenarios:
- Mobile or desktop device usage
- Landing or product category pages, such as those dedicated to Apple or Android products
- User interactions with things like facets
- Date such as promotional periods like Black Friday
- Language such as French and English
- Country such as Germany and Austria.
As well as using this API parameter, you can assign Rule contexts with InstantSearch, Autocomplete, and the Magento and Shopify integrations:
Usage notes
- A Rule context must consist only of alphanumeric characters, hyphens, and underscores
- If
ruleContexts
is empty, only non-contextual Rules are activated. - For performance reasons, you may 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'
]
]);