> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Merchandise on empty queries

> Use an API client or the dashboard to promote or hide items or categories without a particular query.

export const Filter = () => <Tooltip tip="A filter is a condition that limits which records Algolia returns. Filters often use one or more facet-value pairs, such as brand:Apple AND color:red. You can also filter by numeric values, dates, tags, booleans, or geographic constraints." cta="Filtering" href="/doc/guides/managing-results/refine-results/faceting">
    filter
  </Tooltip>;

You can create rules that promote or hide items, boost, or bury categories, or activate filters even when users haven't typed anything yet.

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.
To trigger this rule,  you must send `landing` as a [`ruleContexts`](/doc/api-reference/api-parameters/ruleContexts) on the frontend.

As soon as user begins typing, the rule is turned off.
If you want a rule that's always active for a particular context regardless of the query string, create a [context-only rule](/doc/guides/managing-results/rules/rules-overview#context-only-rules).
For more information, see [Using rules to customize search results by platform](/doc/guides/managing-results/rules/rules-overview/how-to/customize-search-results-by-platform).

<Check>
  To boost, bury, or <Filter /> on values of a certain attribute, you must declare that attribute as an [`attributesForFaceting`](/doc/api-reference/api-parameters/attributesForFaceting).
</Check>

Rules on empty queries are useful for landing or category pages.
Use either [filters](/doc/guides/managing-results/rules/rules-overview#rules-responding-to-applied-filters) or [context](/doc/guides/managing-results/rules/rules-overview#context-only-rules) to determine which category pages should trigger these rules.

For more information, see:

* [Category pages](/doc/guides/solutions/ecommerce/browse/tutorials/category-pages)
* [Merchandise category pages](/doc/guides/managing-results/rules/merchandising-and-promoting/how-to/merchandising-category-pages)

## Using the API

To run the code examples on this page, [install the latest API client](/doc/libraries/sdk/install).

To create a rule with one of the API clients,
use the [`saveRule`](/doc/libraries/sdk/v1/methods/save-rule) method on a rule object with an empty search as the condition.

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.SaveRuleAsync(
    "INDEX_NAME",
    "clearance-category-filter",
    new Rule
    {
      ObjectID = "clearance-category-filter",
      Conditions = new List<Condition>
      {
        new Condition
        {
          Pattern = "",
          Anchoring = Enum.Parse<Anchoring>("Is"),
          Context = "landing",
        },
      },
      Consequence = new Consequence
      {
        Params = new ConsequenceParams
        {
          OptionalFilters = new OptionalFilters("clearance:true"),
        },
      },
    }
  );
  ```

  ```dart Dart theme={"system"}
  final response = await client.saveRule(
    indexName: "INDEX_NAME",
    objectID: "clearance-category-filter",
    rule: Rule(
      objectID: "clearance-category-filter",
      conditions: [
        Condition(
          pattern: "",
          anchoring: Anchoring.fromJson("is"),
          context: "landing",
        ),
      ],
      consequence: Consequence(
        params: ConsequenceParams(
          optionalFilters: "clearance:true",
        ),
      ),
    ),
  );
  ```

  ```go Go theme={"system"}
  response, err := client.SaveRule(client.NewApiSaveRuleRequest(
    "INDEX_NAME", "clearance-category-filter",
    search.NewEmptyRule().SetObjectID("clearance-category-filter").SetConditions(
      []search.Condition{*search.NewEmptyCondition().SetPattern("").SetAnchoring(search.Anchoring("is")).SetContext("landing")}).SetConsequence(
      search.NewEmptyConsequence().SetParams(
        search.NewEmptyConsequenceParams().SetOptionalFilters(search.StringAsOptionalFilters("clearance:true"))))))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  UpdatedAtResponse response = client.saveRule(
    "INDEX_NAME",
    "clearance-category-filter",
    new Rule()
      .setObjectID("clearance-category-filter")
      .setConditions(Arrays.asList(new Condition().setPattern("").setAnchoring(Anchoring.IS).setContext("landing")))
      .setConsequence(new Consequence().setParams(new ConsequenceParams().setOptionalFilters(OptionalFilters.of("clearance:true"))))
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.saveRule({
    indexName: 'indexName',
    objectID: 'clearance-category-filter',
    rule: {
      objectID: 'clearance-category-filter',
      conditions: [{ pattern: '', anchoring: 'is', context: 'landing' }],
      consequence: { params: { optionalFilters: 'clearance:true' } },
    },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.saveRule(
      indexName = "INDEX_NAME",
      objectID = "clearance-category-filter",
      rule =
        Rule(
          objectID = "clearance-category-filter",
          conditions =
            listOf(
              Condition(
                pattern = "",
                anchoring = Anchoring.entries.first { it.value == "is" },
                context = "landing",
              )
            ),
          consequence =
            Consequence(
              params = ConsequenceParams(optionalFilters = OptionalFilters.of("clearance:true"))
            ),
        ),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->saveRule(
      'INDEX_NAME',
      'clearance-category-filter',
      ['objectID' => 'clearance-category-filter',
          'conditions' => [
              ['pattern' => '',
                  'anchoring' => 'is',
                  'context' => 'landing',
              ],
          ],
          'consequence' => ['params' => ['optionalFilters' => 'clearance:true',
          ],
          ],
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.save_rule(
      index_name="INDEX_NAME",
      object_id="clearance-category-filter",
      rule={
          "objectID": "clearance-category-filter",
          "conditions": [
              {
                  "pattern": "",
                  "anchoring": "is",
                  "context": "landing",
              },
          ],
          "consequence": {
              "params": {
                  "optionalFilters": "clearance:true",
              },
          },
      },
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.save_rule(
    "INDEX_NAME",
    "clearance-category-filter",
    Algolia::Search::Rule.new(
      algolia_object_id: "clearance-category-filter",
      conditions: [Algolia::Search::Condition.new(pattern: "", anchoring: "is", context: "landing")],
      consequence: Algolia::Search::Consequence.new(
        params: Algolia::Search::ConsequenceParams.new(optional_filters: "clearance:true")
      )
    )
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.saveRule(
      indexName = "INDEX_NAME",
      objectID = "clearance-category-filter",
      rule = Rule(
        objectID = "clearance-category-filter",
        conditions = Some(
          Seq(
            Condition(
              pattern = Some(""),
              anchoring = Some(Anchoring.withName("is")),
              context = Some("landing")
            )
          )
        ),
        consequence = Consequence(
          params = Some(
            ConsequenceParams(
              optionalFilters = Some(OptionalFilters("clearance:true"))
            )
          )
        )
      )
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response = try await client.saveRule(
      indexName: "INDEX_NAME",
      objectID: "clearance-category-filter",
      rule: Rule(
          objectID: "clearance-category-filter",
          conditions: [SearchCondition(pattern: "", anchoring: SearchAnchoring.`is`, context: "landing")],
          consequence: SearchConsequence(params: SearchConsequenceParams(optionalFilters: SearchOptionalFilters
                  .string("clearance:true")))
      )
  )
  ```
</CodeGroup>

## Using the Visual Editor

1. Select the **Rules** section from the left sidebar menu in the [Algolia dashboard](https://dashboard.algolia.com/rules).
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 drop-down menu, click **Visual Editor**.
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. **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](https://dashboard.algolia.com/rules).

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 drop-down menu, click **Manual Editor**.

4. In the **Condition(s)** section, keep **Query** toggled on,  select **Is**, and leave the text input field empty.

5. If you want to trigger this rule whenever there is an empty query and for this specific context only, toggle **Context** on. In the dedicated input field, enter the context "landing". Without including context as part of the condition, this rule triggers on every empty query.

6. In the **Consequence(s)** section, click **Add consequence** and select **Add Query Parameter**.

7. 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:

   ```json JSON icon=braces theme={"system"}
   {
     "optionalFilters": "clearance:true"
   }
   ```

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.

<Info>
  In JSON, you must write string values inside quotation marks, and number values and booleans without quotations.
</Info>
