Skip to main content
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 an Algolia API client or the Algolia dashboard’s Visual Editor. You can also hide individual items with the Algolia dashboard’s Manual Editor.
You can hide up to 50 items per rule.

Using an API client

This example uses the saveRule method to hide a record if the query contains the word “cheap”.
var response = await client.SaveRuleAsync(
  "ALGOLIA_INDEX_NAME",
  "hide-12345",
  new Rule
  {
    ObjectID = "hide-12345",
    Conditions = new List
    {
      new Condition { Pattern = "cheap", Anchoring = Enum.Parse("Contains") },
    },
    Consequence = new Consequence
    {
      Hide = new List { new ConsequenceHide { ObjectID = "to-hide-12345" } },
    },
  }
);

Using the Visual Editor

  1. Go to the Algolia dashboard and select your Algolia application.
  2. On the left sidebar, select Search.
  3. Select your Algolia index and open the 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 page in the Algolia dashboard.
  2. Select the Rules section from the left sidebar menu in the Algolia dashboard.
  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

I