Guides / Managing results / Rules / Rules Overview

Using Conditionless Rules

The most common use case for Rules is to alter search results depending on a particular condition. However, you can also create Rules that are active for all searches in the Rule’s associated index.

This guide shows you how to create a conditionless Rule, but does not specify the consequence(s). Possible consequences include promoting or hiding items or categories, adding a banner, or adding default search parameters.

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
$rule = array(
    'objectID' => 'a-rule-id',
    'consequence' => array(
      // Set relevant consequence(s)
    )
);

// Set validity (optional)
$rule['validity'] = array(
  array(
    'from' => time(),
    'until' => time() + 30*24*60*60,
  )
);

$index->saveRule($rule);

Using the dashboard

  1. Select the Rules section from the left sidebar menu in the Algolia dashboard.
  2. Under the heading Rules, select the index you are adding a Rule to.
  3. Select Create your first rule or New rule. In the dropdown, click on the Manual Editor option. You cannot create conditionless Rules using the Visual Editor.
  4. In the Condition(s) section, click on Query contains and select All queries.
  5. In the Consequence(s) section, set the relevant consequence(s).
  6. If this rule is only applicable for a certain period of time, select the time range In the Additional Settings, under the Timeframe in UTC header.
  7. If you want to forward the Rule to replicas or other indices, toggle Copy this rule to other indices, and enter the relevant indices.
  8. Don’t forget to save your changes.

Did you find this page helpful?