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

# replaceSynonymsInHighlight

> Whether to replace synonym matches in highlighted results

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="boolean" default="false" scope="settings,search" />

The `replaceSynonymsInHighlight` parameter controls whether highlights and snippets
display the **synonym used in the query** or the **original word from the record**.

For example, with `"home"` as a synonym for `"house"`:

* A query for `"home"` matches records containing `"house"`.
* If this parameter is `true`, the search response shows `"home"` in both highlights and snippets.
* If this parameter is `false`, highlights and snippets show the original word from the record, `"house"`.

## Usage

* One-word synonyms can replace multi-word values in the output.
  However, multi-word queries don't replace shorter synonyms.
  For example, if `"NYC"` and `"New York City"` are synonyms:
  * A query for `"NYC"` will replace `"New York City"` in the highlights.
  * A query for `"New York City"` won't replace `"NYC"` in the highlights.

## Example

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

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

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

      ```java Java theme={"system"}
      UpdatedAtResponse response = client.setSettings("INDEX_NAME", new IndexSettings().setReplaceSynonymsInHighlight(false));
      ```

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

      ```kotlin Kotlin theme={"system"}
      var response =
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(replaceSynonymsInHighlight = false),
        )
      ```

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

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

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

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

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

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

      index.SetSettings(settings);
      ```

      ```go Go theme={"system"}
      res, err := index.SetSettings(search.Settings{
      	ReplaceSynonymsInHighlight: opt.ReplaceSynonymsInHighlight(false),
      })
      ```

      ```java Java theme={"system"}
      index.setSettings(
        new IndexSettings()
          .setReplaceSynonymsInHighlight(true)
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .setSettings({
          replaceSynonymsInHighlight: false,
        })
        .then(() => {
          // done
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val settings = settings {
          replaceSynonymsInHighlight = true
      }

      index.setSettings(settings)
      ```

      ```php PHP theme={"system"}
      $index->setSettings([
        'replaceSynonymsInHighlight' => false
      ]);
      ```

      ```python Python theme={"system"}
      index.set_settings({"replaceSynonymsInHighlight": False})
      ```

      ```ruby Ruby theme={"system"}
      index.set_settings(
        {
          replaceSynonymsInHighlight: false
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        setSettings of "myIndex" `with` IndexSettings(
          replaceSynonymsInHighlight = Some(false)
        )
      }
      ```

      ```swift Swift theme={"system"}
      let settings = Settings()
        .set(\.replaceSynonymsInHighlight, to: false)

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