API Reference / API Parameters / ruleContexts
Type: list of strings
Engine default: []
Parameter syntax
'ruleContexts' => [

Can be used in these methods:

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).


Specify Rule contexts for the current query

$results = $index->search('query', [
  'ruleContexts' => [
Did you find this page helpful?