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

# Add default search parameters with rules

> Learn how to use an API client or the dashboard to add search parameters using always active rules.

export const Index = () => <Tooltip tip="An Algolia index is a searchable dataset that consists of records and configuration settings. These settings define how the records are searched and ranked.">
    index
  </Tooltip>;

You can create rules to add default parameters to every search made to the associated <Index />.
This is most useful when applied with a [validity period](/doc/guides/managing-results/rules/rules-overview#validity-period).
If you want to add always active parameters for an indefinite period of time, you should change your [index's settings](/doc/api-reference/api-parameters).

This page shows you how to create a rule that sets:

* The [`aroundRadius`](/doc/api-reference/api-parameters/aroundRadius) search parameter, for all queries, to 1,000 meters.
* The validity period of this rule to one month.

This an example of a [conditionless rule](/doc/guides/managing-results/rules/rules-overview#conditionless-rules).

## 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 using a rule object without a condition.

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.SaveRuleAsync(
    "INDEX_NAME",
    "a-rule-id",
    new Rule
    {
      ObjectID = "a-rule-id",
      Consequence = new Consequence
      {
        Params = new ConsequenceParams { AroundRadius = new AroundRadius(1000) },
      },
      Validity = new List<TimeRange>
      {
        new TimeRange { From = 1577836800L, Until = 1577836800L },
      },
    }
  );
  ```

  ```dart Dart theme={"system"}
  final response = await client.saveRule(
    indexName: "INDEX_NAME",
    objectID: "a-rule-id",
    rule: Rule(
      objectID: "a-rule-id",
      consequence: Consequence(
        params: ConsequenceParams(
          aroundRadius: 1000,
        ),
      ),
      validity: [
        TimeRange(
          from: 1577836800,
          until: 1577836800,
        ),
      ],
    ),
  );
  ```

  ```go Go theme={"system"}
  response, err := client.SaveRule(client.NewApiSaveRuleRequest(
    "INDEX_NAME", "a-rule-id",
    search.NewEmptyRule().SetObjectID("a-rule-id").SetConsequence(
      search.NewEmptyConsequence().SetParams(
        search.NewEmptyConsequenceParams().SetAroundRadius(search.Int32AsAroundRadius(1000)))).SetValidity(
      []search.TimeRange{*search.NewEmptyTimeRange().SetFrom(1577836800).SetUntil(1577836800)})))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  UpdatedAtResponse response = client.saveRule(
    "INDEX_NAME",
    "a-rule-id",
    new Rule()
      .setObjectID("a-rule-id")
      .setConsequence(new Consequence().setParams(new ConsequenceParams().setAroundRadius(AroundRadius.of(1000))))
      .setValidity(Arrays.asList(new TimeRange().setFrom(1577836800L).setUntil(1577836800L)))
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.saveRule({
    indexName: 'indexName',
    objectID: 'a-rule-id',
    rule: {
      objectID: 'a-rule-id',
      consequence: { params: { aroundRadius: 1000 } },
      validity: [{ from: 1577836800, until: 1577836800 }],
    },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.saveRule(
      indexName = "INDEX_NAME",
      objectID = "a-rule-id",
      rule =
        Rule(
          objectID = "a-rule-id",
          consequence =
            Consequence(params = ConsequenceParams(aroundRadius = AroundRadius.of(1000))),
          validity = listOf(TimeRange(from = 1577836800L, until = 1577836800L)),
        ),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->saveRule(
      'INDEX_NAME',
      'a-rule-id',
      ['objectID' => 'a-rule-id',
          'consequence' => ['params' => ['aroundRadius' => 1000,
          ],
          ],
          'validity' => [
              ['from' => 1577836800,
                  'until' => 1577836800,
              ],
          ],
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.save_rule(
      index_name="INDEX_NAME",
      object_id="a-rule-id",
      rule={
          "objectID": "a-rule-id",
          "consequence": {
              "params": {
                  "aroundRadius": 1000,
              },
          },
          "validity": [
              {
                  "from": 1577836800,
                  "until": 1577836800,
              },
          ],
      },
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.save_rule(
    "INDEX_NAME",
    "a-rule-id",
    Algolia::Search::Rule.new(
      algolia_object_id: "a-rule-id",
      consequence: Algolia::Search::Consequence.new(params: Algolia::Search::ConsequenceParams.new(around_radius: 1000)),
      validity: [Algolia::Search::TimeRange.new(from: 1577836800, _until: 1577836800)]
    )
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.saveRule(
      indexName = "INDEX_NAME",
      objectID = "a-rule-id",
      rule = Rule(
        objectID = "a-rule-id",
        consequence = Consequence(
          params = Some(
            ConsequenceParams(
              aroundRadius = Some(AroundRadius(1000))
            )
          )
        ),
        validity = Some(
          Seq(
            TimeRange(
              from = Some(1577836800L),
              until = Some(1577836800L)
            )
          )
        )
      )
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response = try await client.saveRule(
      indexName: "INDEX_NAME",
      objectID: "a-rule-id",
      rule: Rule(
          objectID: "a-rule-id",
          consequence: SearchConsequence(params: SearchConsequenceParams(aroundRadius: SearchAroundRadius
                  .int(1000))),
          validity: [SearchTimeRange(from: Int64(1_577_836_800), until: Int64(1_577_836_800))]
      )
  )
  ```
</CodeGroup>

## Using the dashboard

1. Select the **Search** product icon on your dashboard.
2. Select the **Rules** section from the left sidebar menu in the [Algolia dashboard](https://dashboard.algolia.com/rules).
3. Under the heading **Rules**, select the index you are adding a Rule to.
4. Select **Create your first rule** or **New rule**. In the drop-down menu, select the **Manual Editor** option.
5. In the **Condition(s)** section, click the **Remove** button with the trash can icon at the top right of the condition.
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: `{ "aroundRadius": 1000 }`
8. In the **Additional Settings**, under the **Timeframe in UTC** header, select a time range of one month.
9. If you want to forward the Rule to replicas or other indices, toggle **Copy this rule to other indices**, and enter the relevant indices.
10. Save your changes.

<Note>
  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 the [record structure guidance](/doc/guides/sending-and-managing-data/prepare-your-data/in-depth/what-is-in-a-record).
</Note>
