🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
API Reference / API Parameters / ruleContexts
Type: list of strings
Engine default: []
Parameter syntax
'ruleContexts' => [
  'context_value',
  ...
]

Can be used in these methods:

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:

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'
  ]
]);
Did you find this page helpful?