Guides / Managing results / Rules / Merchandising and promoting items

Hiding Results with Rules

There are cases when you may want to hide records from users based on what they’re searching for. Rules can help you achieve that, either for a single item or for several.

Hiding a single item

We can use Rules to hide a specific record based on its unique objectID.

Using the API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$rule = [
  'objectID' => 'hide-12345',
  'conditions' => array(array(
    'pattern' => 'query',
    'anchoring' => 'contains'
  )),
  'consequence' => [
    'hide' => [
        'objectID' => 'to-hide-12345'
    ]
  ]
];

$index->saveRule($rule);

Using the dashboard

Visual Editor

  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 Visual Editor option.
  4. In the It all starts here section:
    • Click Set search query button.
    • In the sidepanel, type your query in the input field and click Save.
  5. In the What do you want to do? section:
    • Click the Hide item button.
    • In the sidepanel, find the product you want to hide in the input field and press Save.
  6. Don’t forget to review and publish your changes.

Manual Editor

  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.
  4. In the Condition(s) section, keep Query toggled on, select Contains in the dropdown, and type your query in the input field.
  5. In the Consequence(s) section:
    • Click the Add consequence button and select Hide a result.
    • Find the product you want to hide in the input field and press Enter.
  6. Don’t forget to save your changes.

Hiding a set of items

Hiding single items can be helpful, but most of the time, you’ll want to hide several based on a distinctive attribute.

A good example is when users add key phrases such as “gluten-free”, which you can interpret as a cue to filter out any dish that has “gluten” in its list of allergens.

Did you find this page helpful?