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

# Hide results with rules

> Learn how to use rules to hide records based on the value of specific attributes.

export const Records = () => <Tooltip tip="A record is a searchable object in an Algolia index. Each record consists of named attributes." cta="Algolia records" href="/doc/guides/sending-and-managing-data/prepare-your-data#algolia-records">
    records
  </Tooltip>;

export const Application = () => <Tooltip tip="An Algolia application is a self-contained environment with its own indices, configuration, and API keys. Applications don't share data or settings with each other.">
    application
  </Tooltip>;

export const AlgoliaSearch = () => <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 80" width="20" height="20" className="inline" fill="none" role="presentation" ariaLabel="Algolia Search">
    <circle cx="40" cy="32" r="28" fill="#5468FF"></circle>
    <rect x="30" y="22" width="20" height="20" rx="10" fill="#fff"></rect>
    <path d="M43 63.5 54.5 60l6 17h-12L43 63.5Z" fill="#36395A"></path>
  </svg>;

Sometimes, you may want to use a rule to hide <Records /> based on what users are searching for.
For example, consider a user searching for "cheap laptops" on an ecommerce site.
Without a rule, cheap and premium laptops will appear in the search results.
By applying a rule where:

* Condition: query contains "cheap"
* Consequence: hide items where the `product_range` attribute is `premium`

Users searching for cheap laptops will only see the more affordable options in the search results.

To hide one or more items, use one of the Algolia API clients or the Algolia dashboard's Visual Editor.
You can also hide individual items with the Algolia dashboard's Manual Editor.

<Note>
  You can hide up to 50 items per rule.
</Note>

## Using an API client

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

This example uses the [`saveRule`](/doc/libraries/sdk/v1/methods/save-rule) method to hide a record if the query contains the word "cheap".

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.SaveRuleAsync(
    "INDEX_NAME",
    "hide-12345",
    new Rule
    {
      ObjectID = "hide-12345",
      Conditions = new List<Condition>
      {
        new Condition { Pattern = "cheap", Anchoring = Enum.Parse<Anchoring>("Contains") },
      },
      Consequence = new Consequence
      {
        Hide = new List<ConsequenceHide> { new ConsequenceHide { ObjectID = "to-hide-12345" } },
      },
    }
  );
  ```

  ```dart Dart theme={"system"}
  final response = await client.saveRule(
    indexName: "INDEX_NAME",
    objectID: "hide-12345",
    rule: Rule(
      objectID: "hide-12345",
      conditions: [
        Condition(
          pattern: "cheap",
          anchoring: Anchoring.fromJson("contains"),
        ),
      ],
      consequence: Consequence(
        hide: [
          ConsequenceHide(
            objectID: "to-hide-12345",
          ),
        ],
      ),
    ),
  );
  ```

  ```go Go theme={"system"}
  response, err := client.SaveRule(client.NewApiSaveRuleRequest(
    "INDEX_NAME", "hide-12345",
    search.NewEmptyRule().SetObjectID("hide-12345").SetConditions(
      []search.Condition{*search.NewEmptyCondition().SetPattern("cheap").SetAnchoring(search.Anchoring("contains"))}).SetConsequence(
      search.NewEmptyConsequence().SetHide(
        []search.ConsequenceHide{*search.NewEmptyConsequenceHide().SetObjectID("to-hide-12345")}))))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  UpdatedAtResponse response = client.saveRule(
    "INDEX_NAME",
    "hide-12345",
    new Rule()
      .setObjectID("hide-12345")
      .setConditions(Arrays.asList(new Condition().setPattern("cheap").setAnchoring(Anchoring.CONTAINS)))
      .setConsequence(new Consequence().setHide(Arrays.asList(new ConsequenceHide().setObjectID("to-hide-12345"))))
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.saveRule({
    indexName: 'indexName',
    objectID: 'hide-12345',
    rule: {
      objectID: 'hide-12345',
      conditions: [{ pattern: 'cheap', anchoring: 'contains' }],
      consequence: { hide: [{ objectID: 'to-hide-12345' }] },
    },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.saveRule(
      indexName = "INDEX_NAME",
      objectID = "hide-12345",
      rule =
        Rule(
          objectID = "hide-12345",
          conditions =
            listOf(
              Condition(
                pattern = "cheap",
                anchoring = Anchoring.entries.first { it.value == "contains" },
              )
            ),
          consequence = Consequence(hide = listOf(ConsequenceHide(objectID = "to-hide-12345"))),
        ),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->saveRule(
      'INDEX_NAME',
      'hide-12345',
      ['objectID' => 'hide-12345',
          'conditions' => [
              ['pattern' => 'cheap',
                  'anchoring' => 'contains',
              ],
          ],
          'consequence' => ['hide' => [
              ['objectID' => 'to-hide-12345',
              ],
          ],
          ],
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.save_rule(
      index_name="INDEX_NAME",
      object_id="hide-12345",
      rule={
          "objectID": "hide-12345",
          "conditions": [
              {
                  "pattern": "cheap",
                  "anchoring": "contains",
              },
          ],
          "consequence": {
              "hide": [
                  {
                      "objectID": "to-hide-12345",
                  },
              ],
          },
      },
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.save_rule(
    "INDEX_NAME",
    "hide-12345",
    Algolia::Search::Rule.new(
      algolia_object_id: "hide-12345",
      conditions: [Algolia::Search::Condition.new(pattern: "cheap", anchoring: "contains")],
      consequence: Algolia::Search::Consequence.new(
        hide: [Algolia::Search::ConsequenceHide.new(algolia_object_id: "to-hide-12345")]
      )
    )
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.saveRule(
      indexName = "INDEX_NAME",
      objectID = "hide-12345",
      rule = Rule(
        objectID = "hide-12345",
        conditions = Some(
          Seq(
            Condition(
              pattern = Some("cheap"),
              anchoring = Some(Anchoring.withName("contains"))
            )
          )
        ),
        consequence = Consequence(
          hide = Some(
            Seq(
              ConsequenceHide(
                objectID = "to-hide-12345"
              )
            )
          )
        )
      )
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response = try await client.saveRule(
      indexName: "INDEX_NAME",
      objectID: "hide-12345",
      rule: Rule(
          objectID: "hide-12345",
          conditions: [SearchCondition(pattern: "cheap", anchoring: SearchAnchoring.contains)],
          consequence: SearchConsequence(hide: [SearchConsequenceHide(objectID: "to-hide-12345")])
      )
  )
  ```
</CodeGroup>

## Using the Visual Editor

1. Go to the [Algolia dashboard](https://dashboard.algolia.com/explorer/browse) and select your Algolia <Application />.

2. On the left sidebar, select <AlgoliaSearch /> **Search**.

3. Select your Algolia index and open the [**Rules**](https://dashboard.algolia.com/rules) page.

4. Select **Create your first rule** or **New rule** and select **Visual Editor**.

5. In the **Conditions** section:

   1. Click **Set query condition(s)**.
   2. In the side panel, type your query in the input field, for example, `cheap`, and click **Apply**.

6. In the **Consequences** section:

   1. Click **Hide items**.
   2. Click **Hide by attribute**
   3. In the first box, enter the name of an attribute, such as `product_range`
   4. In the second box, enter a value you want to hide, such as `premium`
   5. Click **Apply**.

7. Click **Review and Publish**.

## Using the Manual Editor

1. Go to the [**Rules**](https://dashboard.algolia.com/rules) page in the Algolia dashboard.

2. Select the **Rules** section from the left sidebar menu in the [Algolia dashboard](https://dashboard.algolia.com/rules).

3. Select **Create your first rule** or **New rule** and select **Manual Editor**.

4. In the **Condition(s)** section, keep **Query** toggled on, select **Contains** in the drop-down menu, and type your query in the input field (for example, `cheap`).

5. In the **Consequence(s)** section:

   1. Click **Add consequence** and select **Hide an item**.
   2. Click the item you want to hide.

6. Click **Save**.

## See also

* [Add filters based on the query](/doc/guides/managing-results/rules/detecting-intent/how-to/applying-a-custom-filter-for-a-specific-query)
* [Dynamic filtering with rules](/doc/guides/managing-results/rules/detecting-intent/how-to/applying-a-filter-if-the-query-match-a-facet-value)
