attributesToHighlight

scope settings search
type array of strings
default all searchable attributes
description

List of attributes to highlight.

If set to null, all searchable attributes are highlighted (see searchableAttributes). The special value * may be used to highlight all attributes.

Only string values can be highlighted. Numerics will be ignored.

When highlighting is enabled, each hit in the response will contain an additional _highlightResult object (provided that at least one of its attributes is highlighted) with the following fields:

  • value (string): Markup text with occurrences highlighted. The tags used for highlighting are specified via highlightPreTag and highlightPostTag.

  • matchLevel (string, enum) = {none | partial | full}: Indicates how well the attribute matched the search query.

  • matchedWords (array): List of words from the query that matched the object.

  • fullyHighlighted (boolean): Whether the entire attribute value is highlighted.

Examples

Set default list of attributes to highlight

<?php
$index->setSettings([
  'attributesToHighlight' => [
    "author",
    "title",
    "content"
  ]
]);
index.set_settings({
  attributesToHighlight: [
    'author',
    'title',
    'content'
  ]
})
index.setSettings({
  attributesToHighlight: [
    'author',
    'title',
    'content'
  ]
});
index.set_settings({
    'attributesToHighlight': [
        'author',
        'title',
        'content'
    ]
})
index.setSettings([
    "attributesToHighlight": [
        "author",
        "title",
        "content"
    ]
])
index.setSettings(new JSONObject().put("attributesToHighlight", 
    new JSONArray().put("author").put("title").put("content")));
index.SetSettings(
  JObject.Parse(@"{""attributesToHighlight"":[""author"", ""title"", ""content""]}")
);
index.setSettings(
  new IndexSettings().setAttributesToHighlight(Arrays.asList(
    "author",
    "title",
    "content"
  ))
);
res, err := index.SetSettings(algoliasearch.Map{
    "attributesToHighlight": []string{
        "author",
        "title",
        "content",
    },
})
client.execute {
  changeSettings of "myIndex" `with` IndexSettings(
    attributesToHighlight = Some(Seq(
      "author",
      "title",
      "content",
    ))
  )
}

Make all attributes highlited by default

<?php
$index->setSettings([
  'attributesToHighlight' => [
    "*"
  ]
]);
index.set_settings({
  attributesToHighlight: [
    '*'
  ]
})
index.setSettings({
  attributesToHighlight: [
    '*'
  ]
});
index.set_settings({
    'attributesToHighlight': [
        '*'
    ]
})
index.setSettings([
    "attributesToHighlight": [
         "*"
    ]
])
index.setSettings(new JSONObject().put("attributesToHighlight", 
    new JSONArray().put("*")));
index.SetSettings(
  JObject.Parse(@"{""attributesToHighlight"":[""*""]}")
);
index.setSettings(
  new IndexSettings().setAttributesToHighlight(Arrays.asList(
    "*"
  ))
);
res, err := index.SetSettings(algoliasearch.Map{
    "attributesToHighlight": []string{
        "*",
    },
})
client.execute {
  changeSettings of "myIndex" `with` IndexSettings(
    attributesToHighlight = Some(Seq(
      "*"
    ))
  )
}
<?php
$results = $index->search('query', [
  'attributesToHighlight' => [
    "title",
    "content"
  ]
]);
results = index.search('query', {
  attributesToHighlight: [
    'title',
    'content'
  ]
})
index.search({
  query: 'query',
  attributesToHighlight: [
    "title",
    "content"
 ]
}).then(res => {
  // console.log(res);
});
results = index.search('query', {
    'attributesToHighlight': [
        'title',
        'content'
    ]
})
let query = Query(query: "query")
query.attributesToHighlight = ["title", "content"]

index.search(query, completionHandler: { (res, error) in
    print(res)
})
index.search(new Query("query").setAttributesToHighlight("title", "content"));
index.search(
  new Query("query").SetAttributesToHighlight(new string[] { "title", "content"})
);
index.search(
  new Query("query").setAttributesToHighlight(Arrays.asList(
    "title",
    "content"
  ))
);
res, err := index.Search("query", algoliasearch.Map{
    "attributesToHighlight": []string{
        "title",
        "content",
    },
})
client.execute {
  search into "myIndex" query Query(
    query = Some("query"),
    attributesToHighlight = Some(Seq(
      "title",
      "content"
    ))
  )
}
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala