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 doesn’t specify the consequences.

Possible consequences include:

Some consequences aren’t available for conditionless Rules. Examples are:

  • Pinning items
  • Editing the query
  • Filtering or boosting matching attributes

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 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 dropdown, click on the Manual Editor option. You can’t create conditionless Rules using the Visual Editor.
  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, set the relevant consequence(s).
  7. 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.
  8. If you want to forward the Rule to replicas or other indices, toggle Copy this rule to other indices, and enter the relevant indices.
  9. Save your changes.
Did you find this page helpful?