🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
Guides / Managing results / Rules / Rules overview

Adding default search parameters with Rules

You can create Rules to add default parameters to every search made to the associated index. This is most useful when applied with a validity period. If you want to add always active parameters for an indefinite period of time, you should change your index’s settings.

This guide shows you how to create a Rule that sets the:

  • aroundRadius search parameter, for all queries, to 1,000 meters,
  • and validity period of this Rule to one month.

This Rule is an example of a conditionless Rule.

Using the API

To create a Rule with an API client, use the saveRule method on a Rule object without a condition.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$rule = array(
    'objectID' => 'a-rule-id',
    'consequence' => array(
        'params' => array(
            'aroundRadius' => 1000,
        )
    )
);

// set validity to 30 days
$rule['validity'] = array(
  array(
    'from' => time(),
    'until' => time() + 30*24*60*60,
  )
);
$index->saveRule($rule);

Using the dashboard

  1. Select the Search product icon on your dashboard.
  2. Select the Rules section from the left sidebar menu in the Algolia dashboard.
  3. Under the heading Rules, select the index you are adding a Rule to.
  4. Select Create your first rule or New rule. In the drop-down menu, select the Manual Editor option.
  5. In the Condition(s) section, click the Remove button with the trash can icon at the top right of the condition.
  6. In the Consequence(s) section, click Add consequence and select Add Query Parameter.
  7. In the input field that appears, enter the JSON search parameter you want to add followed by a colon and the value you want to add. For example: { "aroundRadius": 1000 }

  8. In the Additional Settings, under the Timeframe in UTC header, select a time range of one month.
  9. If you want to forward the Rule to replicas or other indices, toggle Copy this rule to other indices, and enter the relevant indices.
  10. Save your changes.

In JSON, you must write string values inside quotation marks, and number values and booleans without quotations. To get further details on JSON syntax, checkout the record structure guidance.

Did you find this page helpful?