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

# Browse all rules

> Retrieves all rules from an index.

**Required ACL:** `settings`

This helper method iterates over the paginated API response from the
[Search for rules](/doc/rest-api/search/search-rules) API operation
and lets you run an aggregator function on every iteration.

You can use this, for example, to retrieve all rules from your index.

## Usage

<CodeGroup>
  ```cs C# theme={"system"}
  using Algolia.Search.Clients;
  using Algolia.Search.Models.Search;

  var appID = "ALGOLIA_APPLICATION_ID";
  var apiKey = "ALGOLIA_API_KEY";
  var indexName = "ALGOLIA_INDEX_NAME";

  var client = new SearchClient(appID, apiKey);

  var results = await client.BrowseRulesAsync(indexName, new SearchRulesParams {});

  results.ToList().ForEach(rule => Console.WriteLine($"  - Rule: {rule.ObjectID}"));
  ```

  ```go Go theme={"system"}
  package main

  import (
  	"fmt"
  	"log"

  	"github.com/algolia/algoliasearch-client-go/v4/algolia/search"
  )

  func main() {
  	appID := "ALGOLIA_APPLICATION_ID"
  	apiKey := "ALGOLIA_API_KEY"
  	indexName := "ALGOLIA_INDEX_NAME"

  	client, err := search.NewClient(appID, apiKey)
  	if err != nil {
  		log.Fatalln(err)
  	}

  	var rules []search.Rule

  	err = client.BrowseRules(
  		indexName,
  		*search.NewEmptySearchRulesParams(),
  		search.WithAggregator(func(r any, err error) {
  			if err != nil {
  				log.Fatalf("There was an error: %v", err)
  			}

  			rules = append(rules, r.(*search.SearchRulesResponse).Hits...)
  		}),
  	)
  	if err != nil {
  		log.Fatal(err)
  	}

  	for _, rule := range rules {
  		fmt.Printf("- Rule: %s\n", rule.ObjectID)
  	}
  }
  ```

  ```java Java theme={"system"}
  package org.example;

  import com.algolia.api.SearchClient;
  import com.algolia.model.search.SearchRulesParams;
  import java.io.IOException;

  public class Main {

    public static void main(String[] args) throws IOException {
      var appID = "ALGOLIA_APPLICATION_ID";
      var apiKey = "ALGOLIA_API_KEY";
      var indexName = "ALGOLIA_INDEX_NAME";

      var client = new SearchClient(appID, apiKey);

      var response = client.browseRules(indexName, new SearchRulesParams());

      for (var rule : response) {
        System.out.println("- Rule: " + rule.getObjectID());
      }

      client.close();
    }
  }
  ```

  ```js JavaScript theme={"system"}
  import { algoliasearch as searchClient } from "algoliasearch";

  const appId = "ALGOLIA_APPLICATION_ID";
  const apiKey = "ALGOLIA_API_KEY";
  const indexName = "ALGOLIA_INDEX_NAME";

  const client = searchClient(appId, apiKey);

  let rules = [];

  await client.browseRules({
    indexName,
    aggregator: (res) => {
      rules.push(...res.hits);
    },
  });

  rules.forEach((rule) => console.log(`- Rule: ${rule.objectID}`))
  ```

  ```kt Kotlin theme={"system"}
  package org.example

  import com.algolia.client.api.SearchClient
  import com.algolia.client.extensions.browseRules
  import com.algolia.client.model.search.SearchRulesParams
  import com.algolia.client.model.search.SearchRulesResponse
  import com.algolia.client.model.search.Rule

  suspend fun main() {
      val appID = "ALGOLIA_APPLICATION_ID"
      val apiKey = "ALGOLIA_API_KEY"
      val indexName = "ALGOLIA_INDEX_NAME"

      val client = SearchClient(appID, apiKey)

      val rules = mutableListOf<Rule>()

      client.browseRules(
          indexName = indexName,
          searchRulesParams = SearchRulesParams(),
          aggregator = { res: SearchRulesResponse -> rules.addAll(res.hits) })

      rules.forEach { rule -> println("- Rule: ${rule.objectID}") }
  }
  ```

  ```php PHP theme={"system"}
  <?php
  ini_set('memory_limit', '512M');

  require_once realpath(__DIR__.'/vendor/autoload.php');

  use Algolia\AlgoliaSearch\Api\SearchClient;

  $appID = 'ALGOLIA_APPLICATION_ID';
  $apiKey = 'ALGOLIA_API_KEY';
  $indexName = 'ALGOLIA_INDEX_NAME';

  $client = SearchClient::create(appId: $appID, apiKey: $apiKey);

  $res = $client->browseRules($indexName);

  $rules = [];
  foreach ($res as $rule) {
      $rules[] = $rule;
  }

  foreach ($rules as $rule) {
    echo '- rule ' . $rule['objectID'] . "\n";
  }
  ```

  ```python Python theme={"system"}
  from algoliasearch.search.client import SearchClientSync

  app_id = "ALGOLIA_APPLICATION_ID"
  api_key = "ALGOLIA_API_KEY"
  index_name = "ALGOLIA_INDEX_NAME"

  client = SearchClientSync(app_id, api_key)

  rules = []

  _ = client.browse_rules(
      index_name=index_name, aggregator=lambda res: rules.extend(res.hits)
  )

  for rule in rules:
      print(f"- Rule: {rule.object_id}")
  ```

  ```ruby Ruby theme={"system"}
  # frozen_string_literal: true

  require "algolia"

  app_id = "ALGOLIA_APPLICATION_ID"
  api_key = "ALGOLIA_API_KEY"
  index_name = "ALGOLIA_INDEX_NAME"

  client = Algolia::SearchClient.create(app_id, api_key)

  rules = client.browse_rules(index_name)

  rules.each { |rule| puts "- Rule: #{rule.algolia_object_id}" }
  ```

  ```swift Swift theme={"system"}
  import Foundation
  import Search

  let appID = "ALGOLIA_APPLICATION_ID"
  let apiKey = "ALGOLIA_API_KEY"
  let indexName = "ALGOLIA_INDEX_NAME"

  let client = try SearchClient(appID: appID, apiKey: apiKey)

  var rules: [Rule] = []

  func aggregate(resp: SearchRulesResponse) {
    rules.append(contentsOf: resp.hits)
  }

  try await client.browseRules(
    indexName: indexName,
    searchRulesParams: SearchRulesParams(),
    aggregator: aggregate
  )

  for rule in rules {
    print("- Rule: \(rule.objectID)")
  }
  ```
</CodeGroup>

## Parameters

<Tabs>
  <Tab title="C#">
    <ParamField body="indexName" type="string" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="searchRulesParams" type="SearchRulesParams" required>
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Go">
    <ParamField body="indexName" type="string" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="searchRulesParams" type="SearchRulesParams" required>
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="opts..." type="IterableOptions">
      Functional options to provide extra arguments.

      <Expandable title="available functions">
        <ParamField body="search.WithAggregator" type="function">
          **Signature:** `func(aggregator func(any, error)) iterableOption`

          Provides a function that runs on every iteration,
          for example, to aggregate all rules from the response.
        </ParamField>

        <ParamField body="search.WithMaxRetries" type="function">
          **Signature:** `func(maxRetries int) iterableOption`

          Sets the maximum number of iterations for this method.
          For example, with `search.WithMaxRetries(1)`
          this method stops after the first request.
          By default,
          `BrowseRules` iterates through all pages of the API response.
        </ParamField>

        <ParamField body="search.WithTimeout" type="function">
          **Signature:** `func(timeout func(count int) time.Duration) iterableOption`

          Provides a function for calculating the waiting time between requests.
          The timeout function accepts the iteration count as parameter.
          This lets you implement varying timeouts.
        </ParamField>

        <ParamField body="search.WithHeaderParams" type="function">
          **Signature:** `func(key string, value string) requestOption`

          Sets extra header parameters for this request.
          To learn more, see [Request options](/doc/libraries/sdk/request-options).
        </ParamField>

        <ParamField body="search.WithQueryParam" type="function">
          **Signature:** `func(key string, value string) requestOption`

          Sets extra query parameters for this request.
          To learn more, see [Request options](/doc/libraries/sdk/request-options).
        </ParamField>
      </Expandable>
    </ParamField>
  </Tab>

  <Tab title="Java">
    <ParamField body="indexName" type="String" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="searchRulesParams" type="SearchRulesParams" required>
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="JavaScript">
    <ParamField body="indexName" type="string" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="aggregator" type="function" required>
      **Signature:** `(SearchRulesResponse) => void`

      A function that runs on every iteration,
      for example, to aggregate all rules from the response.
    </ParamField>

    <ParamField body="searchRulesParams" type="SearchRulesParams">
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="validate" type="function">
      **Signature:** `(SearchRulesResponse) => bool`

      A function that returns true when the iteration should stop.
      By default, the iteration stops if the API response returns fewer than `hitsPerPage` hits.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Kotlin">
    <ParamField body="indexName" type="String" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="searchRulesParams" type="SearchRulesParams" required>
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="aggregator" type="function" required>
      **Signature:** `(SearchRulesResponse) -> Unit`

      A function that runs on every iteration, for example,
      to aggregate all rules from the response.
    </ParamField>

    <ParamField body="validate" type="function">
      **Signature:** `(SearchRulesResponse) -> Boolean`

      A function that returns true when the iteration should stop.
      By default, the iteration stops if the API response returns fewer than `hitsPerPage` hits.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="PHP">
    <ParamField body="indexName" type="string" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="requestOptions" type="array">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Python">
    <ParamField body="index_name" type="str" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="aggregator" type="function" required>
      **Signature:** `(SearchRulesResponse) -> None`

      A function that runs on every iteration,
      for example, to aggregate all rules from the response.
    </ParamField>

    <ParamField body="search_rules_params" type="SearchRulesParams | None">
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="request_options" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Ruby">
    <ParamField body="index_name" type="String" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="search_rules_params" type="SearchRulesParams">
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="request_options" type="Hash">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Scala">
    <ParamField body="indexName" type="String" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="searchRulesParams" type="SearchRulesParams" required>
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="aggregator" type="function" required>
      **Signature:** `SearchRulesResponse => Unit`

      A function that runs on every iteration, for example,
      to aggregate all records from the response.
    </ParamField>

    <ParamField body="validate" type="function">
      **Signature:** `SearchRulesResponse => Boolean`

      A function that returns true when the iteration should stop.
      By default, the iteration stops if the API response doesn't contain a `cursor` field.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>

  <Tab title="Swift">
    <ParamField body="indexName" type="String" required>
      Index name from which to retrieve the rules.
    </ParamField>

    <ParamField body="searchRulesParams" type="SearchRulesParams" required>
      Parameters for the [Search for rules](/doc/rest-api/search/search-rules) request.
    </ParamField>

    <ParamField body="aggregator" type="function" required>
      **Signature:** `(SearchRulesResponse) -> Void`

      A function that runs on every iteration, for example,
      to aggregate all records from the response.
    </ParamField>

    <ParamField body="validate" type="function">
      **Signature:** `(SearchRulesResponse) -> Bool`

      A function that returns true when the iteration should stop.
      By default, the iteration stops if the API response doesn't contain a `cursor` field.
    </ParamField>

    <ParamField body="requestOptions" type="RequestOptions">
      Additional [request options](/doc/libraries/sdk/request-options).
    </ParamField>
  </Tab>
</Tabs>
