Guides / Managing results / Rules / Merchandising and promoting items

Merchandising on Empty Queries

You can create Rules that promote or hide items, boost or bury categories, or activate filters even when the user hasn’t typed anything yet. These Rules are useful for landing or category pages. On category pages, it’s necessary to use a context to differentiate between which category pages should trigger these Rules.

This guide shows you how to create a Rule that boosts the category clearance:true, whenever there is an empty query and the context is set to landing. You can use other consequences, such as promoting or hiding items, and boosting or burying categories, with the same condition. Note, to trigger this Rule, you must send landing as a ruleContexts on the front end.

As soon as user begins typing, we disable the Rule. If you want a Rule that is always active for a particular context regardless of the query string, create a Rule with context as the only condition. Our guide on using Rules to customize search results by platform shows how to create context based rules.

If you have several similar Rules, one for each category page for example, it is most efficient to use the API to create and save multiple rules programmatically.

To boost, bury, or filter on values of a certain attribute, you must declare that attribute as an attributesForFaceting.

Using the API

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// turn json into an array
$rule = array(
    'objectID' => 'clearance-category-filter',
    'conditions' => array(
      array(
        'pattern' => '',
        'anchoring' => 'is'
      ),
      array(
        'context' => 'landing',
      ),
    ),
    'consequence' => array(
        'params' => array(
            'optionalFilters' => 'clearance:true'
        )
    )
);
// push Rule to index
$index->saveRule($rule);

Using the 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. Select Set the search query.
  5. In the Your search section, right below the Define the query that triggers the rule header, select is and leave the next input box empty.
  6. In Add a context (optional), add the context “landing”. If you want to trigger this Rule whenever there is an empty query, regardless of context, leave this input box empty. Select Apply.
  7. Below What do you want to do? Select Boost categories.
  8. Fill in the Category section to be “clearance” is “true”.
  9. Select Apply. This will provide you a preview of the results.
  10. Before exiting, don’t forget to Save as Draft or Review and Publish.

Using the 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, click on Context is and enter “landing”. If you want to trigger this Rule whenever there is an empty query and regardless of context, select Query is and leave the next input box empty.
  5. In the Consequence(s) section, click on Add consequence and select Add Query Parameter.
  6. 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:
    1
    2
    3
    
    {
      "optionalFilters": "clearance:true"
    }
    
  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.

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 our page on record structure.

Did you find this page helpful?