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

# typoTolerance

> Controls whether typo tolerance is on and how it's applied

export const Setting = ({type, default: defaultValue, defaultNote, scope, min, max, formerly}) => {
  const renderedDefault = defaultValue === '' ? '""' : defaultValue;
  const renderedNote = defaultNote ? `(${defaultNote})` : '';
  return <ul>
      <li><strong>Type:</strong> <code>{type}</code></li>
      <li><strong>Default:</strong> <code>{renderedDefault}</code>{renderedNote}</li>
      {min && <li><strong>Min:</strong> <code>{min}</code></li>}
      {max && <li><strong>Max:</strong> <code>{max}</code></li>}
      <li><strong>Scope:</strong> <a href="/doc/api-reference/api-parameters"><code>{scope}</code></a></li>
      {formerly && <li>
          <strong>Deprecated name:</strong> <code>{formerly}</code>
        </li>}
    </ul>;
};

<Setting type="enum<string> | boolean" default="true" scope="settings,search" />

This parameter controls if Algolia considers matches with typos when searching,
and how aggressively.

To learn more, see [Configuring typo tolerance](/doc/guides/managing-results/optimize-search-results/typo-tolerance/in-depth/configuring-typo-tolerance).

## Usage

* Use [`getRankingInfo`](/doc/api-reference/api-parameters/getRankingInfo) to inspect the typo count per record.
* Algolia generally doesn't return results with more than **two typos**, unless [the first letter is mistyped](/doc/guides/managing-results/optimize-search-results/typo-tolerance#calculating-distance).

<Info>
  By default, Algolia matches query terms at the **beginning of words** in your records (prefix matching). For alternatives, see [Match queries in the middle or end of words](/doc/guides/managing-results/optimize-search-results/override-search-engine-defaults/how-to/how-can-i-make-queries-within-the-middle-of-a-word).
</Info>

## Options

<ParamField path="true | &#x22;true&#x22;">
  Typo tolerance is enabled for all attributes and query words (default behavior).
  Accepts both `true` (boolean) and `"true"` (string).
  Also enables [splitting and concatenation](/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/splitting-and-concatenation).
</ParamField>

<ParamField path="false | &#x22;false&#x22;">
  Typo tolerance is off. Only exact matches will be returned.
  Accepts both `false` (boolean) and `"false"` (string).
</ParamField>

<ParamField path="min">
  Applies typo tolerance but returns only the records with the **fewest typos**.
  For example, if results include matches with one and two typos, only those with one typo are returned.
  Also enables [splitting and concatenation](/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/splitting-and-concatenation).
</ParamField>

<ParamField path="strict">
  Like `"min"`, but includes results with the **fewest and second fewest** typos.
  Also forces the [Typo ranking criterion](/doc/guides/managing-results/relevance-overview/in-depth/ranking-criteria#typo) to be evaluated first in the ranking formula.
  Also enables [splitting and concatenation](/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/splitting-and-concatenation).
</ParamField>

## Examples

### Set default typo tolerance mode

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen="true">
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SetSettingsAsync(
        "INDEX_NAME",
        new IndexSettings { TypoTolerance = new TypoTolerance(true) }
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.setSettings(
        indexName: "INDEX_NAME",
        indexSettings: IndexSettings(
          typoTolerance: true,
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SetSettings(client.NewApiSetSettingsRequest(
        "INDEX_NAME",
        search.NewEmptyIndexSettings().SetTypoTolerance(search.BoolAsTypoTolerance(true))))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      UpdatedAtResponse response = client.setSettings("INDEX_NAME", new IndexSettings().setTypoTolerance(TypoTolerance.of(true)));
      ```

      ```js JavaScript theme={"system"}
      const response = await client.setSettings({ indexName: 'theIndexName', indexSettings: { typoTolerance: true } });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(typoTolerance = TypoTolerance.of(true)),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->setSettings(
          'INDEX_NAME',
          ['typoTolerance' => true,
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.set_settings(
          index_name="INDEX_NAME",
          index_settings={
              "typoTolerance": True,
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.set_settings("INDEX_NAME", Algolia::Search::IndexSettings.new(typo_tolerance: true))
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(
            typoTolerance = Some(TypoTolerance(true))
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response = try await client.setSettings(
          indexName: "INDEX_NAME",
          indexSettings: IndexSettings(typoTolerance: SearchTypoTolerance.bool(true))
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      IndexSettings settings = new IndexSettings();
      settings.TypoTolerance = true;
      // settings.TypoTolerance = false;
      // settings.TypoTolerance = "min";
      // settings.TypoTolerance = "strict";
      ```

      ```go Go theme={"system"}
      res, err := index.SetSettings(search.Settings{
      	TypoTolerance: opt.TypoTolerance(true),
      	// TypoTolerance: opt.TypoTolerance(false),
      	// TypoTolerance: opt.TypoToleranceMin(),
      	// TypoTolerance: opt.TypoToleranceStrict(),
      })
      ```

      ```java Java theme={"system"}
      index.setSettings(
        new IndexSettings().setTypoTolerance(TypoTolerance.of(true))
        // new IndexSettings().setTypoTolerance(TypoTolerance.of(false))
        // new IndexSettings().setTypoTolerance(TypoTolerance.of("min"))
        // new IndexSettings().setTypoTolerance(TypoTolerance.of("strict"))
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .setSettings({
          typoTolerance: true,
          // typoTolerance: false
          // typoTolerance: 'min'
          // typoTolerance: 'strict'
        })
        .then(() => {
          // done
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val settings = settings {
          typoTolerance = TypoTolerance.True
          // typoTolerance = TypoTolerance.False
          // typoTolerance = TypoTolerance.Min
          // typoTolerance = TypoTolerance.Strict
      }

      index.setSettings(settings)
      ```

      ```php PHP theme={"system"}
      $index->setSettings([
        'typoTolerance' => true
        // 'typoTolerance' => false
        // 'typoTolerance' => 'min'
        // 'typoTolerance' => 'strict'
      ]);
      ```

      ```python Python theme={"system"}
      index.set_settings(
          {
              "typoTolerance": True
              # 'typoTolerance': False
              # 'typoTolerance': 'min'
              # 'typoTolerance': 'strict'
          }
      )
      ```

      ```ruby Ruby theme={"system"}
      index.set_settings(
        {
          typoTolerance: true
          # typoTolerance: false
          # typoTolerance: 'min'
          # typoTolerance: 'strict'
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        setSettings of "myIndex" `with` IndexSettings(
          typoTolerance = Some(TypoTolerance.`true`)
          // typoTolerance = Some(TypoTolerance.`false`)
          // typoTolerance = Some(TypoTolerance.min)
          // typoTolerance = Some(TypoTolerance.strict)
        )
      }
      ```

      ```swift Swift theme={"system"}
      let settings = Settings()
        .set(\.typoTolerance, to: true)
      //.set(\.typoTolerance, to: false)
      //.set(\.typoTolerance, to: .min)
      //.set(\.typoTolerance, to: .strict)

      index.setSettings(settings) { result in
        if case .success(let response) = result {
          print("Response: \(response)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>

### Override default typo tolerance mode for the current search

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen>
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SearchSingleIndexAsync<Hit>(
        "INDEX_NAME",
        new SearchParams(
          new SearchParamsObject { Query = "query", TypoTolerance = new TypoTolerance(false) }
        )
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.searchSingleIndex(
        indexName: "INDEX_NAME",
        searchParams: SearchParamsObject(
          query: "query",
          typoTolerance: false,
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
        "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
        search.NewEmptySearchParamsObject().SetQuery("query").SetTypoTolerance(search.BoolAsTypoTolerance(false)))))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      SearchResponse response = client.searchSingleIndex(
        "INDEX_NAME",
        new SearchParamsObject().setQuery("query").setTypoTolerance(TypoTolerance.of(false)),
        Hit.class
      );
      ```

      ```js JavaScript theme={"system"}
      const response = await client.searchSingleIndex({
        indexName: 'indexName',
        searchParams: { query: 'query', typoTolerance: false },
      });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = SearchParamsObject(query = "query", typoTolerance = TypoTolerance.of(false)),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->searchSingleIndex(
          'INDEX_NAME',
          ['query' => 'query',
              'typoTolerance' => false,
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.search_single_index(
          index_name="INDEX_NAME",
          search_params={
              "query": "query",
              "typoTolerance": False,
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.search_single_index(
        "INDEX_NAME",
        Algolia::Search::SearchParamsObject.new(query: "query", typo_tolerance: false)
      )
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams = Some(
            SearchParamsObject(
              query = Some("query"),
              typoTolerance = Some(TypoTolerance(false))
            )
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response: SearchResponse<Hit> = try await client.searchSingleIndex(
          indexName: "INDEX_NAME",
          searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
              query: "query",
              typoTolerance: SearchTypoTolerance.bool(false)
          ))
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      index.Search(new Query("query")
      {
          TypoTolerance = true
          // TypoTolerance = false
          // TypoTolerance = "min"
          // TypoTolerance = "strict"
      });
      ```

      ```go Go theme={"system"}
      res, err := index.Search(
      	"query",
      	opt.TypoTolerance(false),
      	// opt.TypoTolerance(true),
      	// opt.TypoToleranceMin(),
      	// opt.TypoToleranceStrict(),
      )
      ```

      ```java Java theme={"system"}
      index.search(
        new Query("").setTypoTolerance(TypoTolerance.of(false))
        // new Query("").setTypoTolerance(TypoTolerance.of(true)))
        // new Query("").setTypoTolerance(TypoTolerance.of("min"))
        // new Query("").setTypoTolerance(TypoTolerance.of("strict"))
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .search("query", {
          typoTolerance: false,
          // 'typoTolerance': true
          // 'typoTolerance': 'min'
          // 'typoTolerance': 'strict'
        })
        .then(({ hits }) => {
          console.log(hits);
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val query = query("query") {
          typoTolerance = TypoTolerance.True
          // typoTolerance = TypoTolerance.False
          // typoTolerance = TypoTolerance.Min
          // typoTolerance = TypoTolerance.Strict
      }

      index.search(query)
      ```

      ```php PHP theme={"system"}
      $results = $index->search('query', [
        'typoTolerance' => false
        // 'typoTolerance' => true
        // 'typoTolerance' => 'min'
        // 'typoTolerance' => 'strict'
      ]);
      ```

      ```python Python theme={"system"}
      results = index.search(
          "query",
          {
              "typoTolerance": False
              # 'typoTolerance': True
              # 'typoTolerance': 'min'
              # 'typoTolerance': 'strict'
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      results = index.search(
        "query",
        {
          typoTolerance: false
          # typoTolerance: true
          # typoTolerance: 'min'
          # typoTolerance: 'strict'
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        search into "myIndex" query Query(
          query = Some("query"),
          typoTolerance = Some(TypoTolerance.`false`)
          // typoTolerance = Some(TypoTolerance.`true`)
          // typoTolerance = Some(TypoTolerance.min)
          // typoTolerance = Some(TypoTolerance.strict)
        )
      }
      ```

      ```swift Swift theme={"system"}
      let query = Query("query")
        .set(\.typoTolerance, to: false)
        //.set(\.typoTolerance, to: true)
        //.set(\.typoTolerance, to: .min)
        //.set(\.typoTolerance, to: .strict)

      index.search(query: query) { result in
        if case .success(let response) = result {
          print("Response: \(response)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
