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

# attributesToHighlight

> Attributes to highlight

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="list<string>" default="null" defaultNote="all searchable attributes" scope="settings,search" />

## Usage

* By default, all [searchable attributes](/doc/api-reference/api-parameters/searchableAttributes) are highlighted.
* The special value `*` may be used to highlight all attributes.
* Pass an empty array (`[]`) to turn off highlighting.
* Algolia highlights the first 50,000 characters of the whole result set (5,000 logograms for CJK languages).
  This limit prevents impacting the user experience by ensuring a fast response time even with large results.
* When highlighting is enabled, each hit in the response contains a `_highlightResult` object.
* When enabled, each hit includes a `_highlightResult` object with metadata about the matches.

### `_highlightResult`

<Expandable defaultOpen="true">
  <ParamField path="_highlightResult.value" type="string">
    Matching text, surrounded by HTML tags defined in the [`highlightPreTag`](/doc/api-reference/api-parameters/highlightPreTag)
    and [`highlightPostTag`](/doc/api-reference/api-parameters/highlightPostTag) settings.
  </ParamField>

  <ParamField path="_highlightResult.matchLevel" type="enum<string>">
    Indicates how well the attribute matched the search query.
    Possible values are `none`, `partial`, `full`.
  </ParamField>

  <ParamField path="_highlightResult.matchedWords" type="list<string>">
    List of query words that matched the record.
  </ParamField>

  <ParamField path="_highlightResult.fullyHighlighted" type="boolean">
    Whether the entire attribute value is highlighted.
  </ParamField>
</Expandable>

## Examples

### Set default list of attributes to highlight

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

      ```dart Dart theme={"system"}
      final response = await client.setSettings(
        indexName: "INDEX_NAME",
        indexSettings: IndexSettings(
          attributesToHighlight: [
            "author",
            "title",
            "content",
          ],
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SetSettings(client.NewApiSetSettingsRequest(
        "INDEX_NAME",
        search.NewEmptyIndexSettings().SetAttributesToHighlight(
          []string{"author", "title", "content"})))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      UpdatedAtResponse response = client.setSettings(
        "INDEX_NAME",
        new IndexSettings().setAttributesToHighlight(Arrays.asList("author", "title", "content"))
      );
      ```

      ```js JavaScript theme={"system"}
      const response = await client.setSettings({
        indexName: 'theIndexName',
        indexSettings: { attributesToHighlight: ['author', 'title', 'content'] },
      });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(attributesToHighlight = listOf("author", "title", "content")),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->setSettings(
          'INDEX_NAME',
          ['attributesToHighlight' => [
              'author',

              'title',

              'content',
          ],
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.set_settings(
          index_name="INDEX_NAME",
          index_settings={
              "attributesToHighlight": [
                  "author",
                  "title",
                  "content",
              ],
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.set_settings(
        "INDEX_NAME",
        Algolia::Search::IndexSettings.new(attributes_to_highlight: ["author", "title", "content"])
      )
      ```

      ```scala Scala theme={"system"}
      val response = Await.result(
        client.setSettings(
          indexName = "INDEX_NAME",
          indexSettings = IndexSettings(
            attributesToHighlight = Some(Seq("author", "title", "content"))
          )
        ),
        Duration(100, "sec")
      )
      ```

      ```swift Swift theme={"system"}
      let response = try await client.setSettings(
          indexName: "INDEX_NAME",
          indexSettings: IndexSettings(attributesToHighlight: ["author", "title", "content"])
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      IndexSettings settings = new IndexSettings()
      settings.AttributesToHighlight = new List
      {
          "author",
          "title",
          "content"
      };

      index.SetSettings(settings);
      ```

      ```go Go theme={"system"}
      res, err := index.SetSettings(search.Settings{
      	AttributesToHighlight: opt.AttributesToHighlight(
      		"author",
      		"title",
      		"content",
      	),
      })
      ```

      ```java Java theme={"system"}
      index.setSettings(
        new IndexSettings()
          .setAttributesToHighlight(Arrays.asList(
            "author",
            "title",
            "content"
          ))
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .setSettings({
          attributesToHighlight: ["author", "title", "content"],
        })
        .then(() => {
          // done
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val settings = settings {
          attributesToHighlight {
              +"author"
              +"title"
              +"content"
          }
      }

      index.setSettings(settings)
      ```

      ```php PHP theme={"system"}
      $index->setSettings([
        'attributesToHighlight' => [
          "author",
          "title",
          "content"
        ]
      ]);
      ```

      ```python Python theme={"system"}
      index.set_settings({"attributesToHighlight": ["author", "title", "content"]})
      ```

      ```ruby Ruby theme={"system"}
      index.set_settings(
        {
          attributesToHighlight: [
            "author",
            "title",
            "content"
          ]
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        setSettings of "myIndex" `with` IndexSettings(
          attributesToHighlight = Some(Seq(
            "author",
            "title",
            "content",
          ))
        )
      }
      ```

      ```swift Swift theme={"system"}
      let settings = Settings()
        .set(\.attributesToHighlight, to: [
          "author",
          "title",
          "content"
        ])

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

### Make all attributes highlighted by default

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

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

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

      ```java Java theme={"system"}
      UpdatedAtResponse response = client.setSettings("INDEX_NAME", new IndexSettings().setAttributesToHighlight(Arrays.asList("*")));
      ```

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

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

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

      ```python Python theme={"system"}
      response = client.set_settings(
          index_name="INDEX_NAME",
          index_settings={
              "attributesToHighlight": [
                  "*",
              ],
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.set_settings(
        "INDEX_NAME",
        Algolia::Search::IndexSettings.new(attributes_to_highlight: ["*"])
      )
      ```

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

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

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


      index.SetSettings(settings);
      ```

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

      ```java Java theme={"system"}
      index.setSettings(
        new IndexSettings()
          .setAttributesToHighlight(Arrays.asList(
            "*"
          ))
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .setSettings({
          attributesToHighlight: ["*"],
        })
        .then(() => {
          // done
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val query = query("query") {
          attributesToHighlight {
              +"*"
          }
      }

      index.search(query)
      ```

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

      ```python Python theme={"system"}
      index.set_settings({"attributesToHighlight": ["*"]})
      ```

      ```ruby Ruby theme={"system"}
      index.set_settings(
        {
          attributesToHighlight: [
            "*"
          ]
        }
      )
      ```

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

      ```swift Swift theme={"system"}
      let settings = Settings()
        .set(\.attributesToHighlight, to: [
          "*"
        ])

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

### Override list of attributes to highlight 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",
            AttributesToHighlight = new List<string> { "title", "content" },
          }
        )
      );
      ```

      ```dart Dart theme={"system"}
      final response = await client.searchSingleIndex(
        indexName: "INDEX_NAME",
        searchParams: SearchParamsObject(
          query: "query",
          attributesToHighlight: [
            "title",
            "content",
          ],
        ),
      );
      ```

      ```go Go theme={"system"}
      response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
        "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
        search.NewEmptySearchParamsObject().SetQuery("query").SetAttributesToHighlight(
          []string{"title", "content"}))))
      if err != nil {
        // handle the eventual error
        panic(err)
      }
      ```

      ```java Java theme={"system"}
      SearchResponse response = client.searchSingleIndex(
        "INDEX_NAME",
        new SearchParamsObject().setQuery("query").setAttributesToHighlight(Arrays.asList("title", "content")),
        Hit.class
      );
      ```

      ```js JavaScript theme={"system"}
      const response = await client.searchSingleIndex({
        indexName: 'indexName',
        searchParams: { query: 'query', attributesToHighlight: ['title', 'content'] },
      });
      ```

      ```kotlin Kotlin theme={"system"}
      var response =
        client.searchSingleIndex(
          indexName = "INDEX_NAME",
          searchParams =
            SearchParamsObject(query = "query", attributesToHighlight = listOf("title", "content")),
        )
      ```

      ```php PHP theme={"system"}
      $response = $client->searchSingleIndex(
          'INDEX_NAME',
          ['query' => 'query',
              'attributesToHighlight' => [
                  'title',

                  'content',
              ],
          ],
      );
      ```

      ```python Python theme={"system"}
      response = client.search_single_index(
          index_name="INDEX_NAME",
          search_params={
              "query": "query",
              "attributesToHighlight": [
                  "title",
                  "content",
              ],
          },
      )
      ```

      ```ruby Ruby theme={"system"}
      response = client.search_single_index(
        "INDEX_NAME",
        Algolia::Search::SearchParamsObject.new(query: "query", attributes_to_highlight: ["title", "content"])
      )
      ```

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

      ```swift Swift theme={"system"}
      let response: SearchResponse<Hit> = try await client.searchSingleIndex(
          indexName: "INDEX_NAME",
          searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
              query: "query",
              attributesToHighlight: ["title", "content"]
          ))
      )
      ```
    </CodeGroup>
  </Accordion>

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      index.Search(new Query("query")
      {
          AttributesToHighlight = new List { "title", "content" }
      });
      ```

      ```go Go theme={"system"}
      res, err := index.Search(
      	"query",
      	opt.AttributesToHighlight("title", "content"),
      )
      ```

      ```java Java theme={"system"}
      index.search(
        new Query("query")
          .setAttributesToHighlight(
            Arrays.asList(
              "title",
              "content"
            )
          )
      );
      ```

      ```js JavaScript theme={"system"}
      index
        .search("query", {
          attributesToHighlight: ["title", "content"],
        })
        .then(({ hits }) => {
          console.log(hits);
        });
      ```

      ```php PHP theme={"system"}
      $results = $index->search('query', [
        'attributesToHighlight' => [
          "title",
          "content"
        ]
      ]);
      ```

      ```python Python theme={"system"}
      results = index.search("query", {"attributesToHighlight": ["title", "content"]})
      ```

      ```ruby Ruby theme={"system"}
      results = index.search(
        "query",
        {
          attributesToHighlight: [
            "title",
            "content"
          ]
        }
      )
      ```

      ```scala Scala theme={"system"}
      client.execute {
        search into "myIndex" query Query(
          query = Some("query"),
          attributesToHighlight = Some(Seq(
            "title",
            "content"
          ))
        )
      }
      ```

      ```swift Swift theme={"system"}
      let query = Query("query")
        .set(\.attributesToHighlight, to: [
          "title",
          "content"
        ])

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