Guides / Managing results / Rules / Merchandising and promoting items

Promoting Hits

You can use Rules to raise some results over others, or put one result or banner at the top of the results.

Promoting a single item

Use Case

A book store wants to recommend a Harry Potter Box Set whenever the words Harry Potter form part of a search.

Rule

If query=Harry Potter then promote Harry Potter Box Set

Using the API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Turn JSON into an array
$rule = array(
  'objectID' => 'promote-harry-potter-box-set',
  'conditions' => array(array(
    'pattern' => 'Harry Potter',
    'anchoring' => 'contains'
  )),
  'consequence' => array(
    'promote' => array(
       array(
          'objectID' => 'HP-12345',
          'position'=> 0 // objectID 'HP-12345' ==> Harry Potter Box Set
       )
    )
  )
);

// Push Rule to index
$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 “Harry Potter” in the input field and click Save.
  5. In the Strategy section:
    • Click the Pin item button.
    • In the sidepanel, find the product ‘HP-12345’ you want to pin 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 contains and enter “Harry Potter” in the input field.
  5. In the Consequence(s) section:
    • Click the Add consequence button and select Pin an item.
    • Find the product ‘HP-12345’ you want to pin the input field and press Enter.
  6. Don’t forget to save your changes.

Promoting the newest release

Use Case

You’ve placed “best-selling items” at the top of your search results by using Custom Ranking. But the newest release? Set up a Rule telling the engine that whenever iPhone is searched for, place the newest version at the top, but for the rest of the same brand phones, continue sorting by most-sold.

Rule

If query = iphone then promote newest iphone release

Using the API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Turn JSON into an array
$rule = array(
  'objectID' => 'Promote-iPhone-X',
  'conditions' => array(array(
    'pattern' => 'iPhone',
    'anchoring' => 'contains'
  )),
  'consequence' => array(
    'promote' => array(
      array(
        'objectID' => 'iPhone-12345',
        'position' => 0 // objectID 'iPhone-12345' ==> iPhone X (newest release)
      )
    )
  )
);

// Push Rule to index
$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 “iPhone” in the input field and click Save.
  5. In the Strategy section:
    • Click the Pin item button.
    • In the sidepanel, find the product “iPhone-12345” you want to pin 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 enter “iPhone” in the input field.
  5. In the Consequence(s) section:
    • Click the Add consequence button and select Pin an item.
    • Find the product “iPhone-12345” you want to pin the input field and press Enter.
  6. Don’t forget to save your changes.

Promoting some results over others

Note: This only applies to Premium plans.

Use Case

Tomato: A simple search, but one that may never return the fruit (or vegetable) because too many Tomato Soup brands are selling better than cherry tomatoes.

Rule

If query=tomato then put fruits higher than the rest

Using the API

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Turn JSON into an array
$rule = array(
    'objectID' => 'tomato-fruit',
    'conditions' => array(array(
        'pattern' => 'tomato',
        'anchoring' => 'contains'
    )),
    'consequence' => array(
        'params' => array(
            'optionalFilters' => 'food_group:fruit'
        )
    )
);
// Push Rule to index
$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 “tomato” in the input field and click Save.
  5. In the Strategy section:
    • Click the Boost Categories button.
    • In the side panel, type “food_group” in the input field for category, then “fruit” in the second 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 enter “tomato” in the input field.
  5. In the Consequence(s) section:
    • Click the Add consequence button and select Add Query Parameter.
    • Type {"optionalFilters":"food_group:fruit"}.
  6. Don’t forget to save your changes.

Did you find this page helpful?