attributesToHighlight

Type: list of strings
Engine default: all searchable attributes
Parameter syntax
'attributesToHighlight' => [
  'attribute',
  '*', // returns all attributes in the index not just searchable attributes
  ...
]
Parameter syntax
attributesToHighlight: [
  'attribute',
  '*', # returns all attributes in the index not just searchable attributes
  ...
]
Parameter syntax
attributesToHighlight: [
  'attribute',
  '*', // returns all attributes in the index not just searchable attributes
  ...
]
Parameter syntax
'attributesToHighlight': [
  'attribute',
  '*', # returns all attributes in the index not just searchable attributes
  ...
]
Parameter syntax
"attributesToHighlight": [
  "attribute",
  "*" // returns all attributes in the index not just searchable attributes
]
Parameter syntax
new JSONObject()
  .put(
    "attributesToHighlight",
    new JSONArray()
      .put("attribute")
      .put("*") // returns all attributes in the index not just searchable attributes
  )
Parameter syntax
dynamic settings = new JObject();
settings.attributesToHighlight = new JArray()
  .put("attribute")
  .put("*") // returns all attributes in the index not just searchable attributes
  ...
Parameter syntax
.setAttributesToHighlight(Arrays.asList(
  "attribute",
  "*" // returns all attributes in the index not just searchable attributes
))
Parameter syntax
"attributesToHighlight": []string{
  "attribute",
  "*" // returns all attributes in the index not just searchable attributes
}
Parameter syntax
attributesToHighlight = Some(Seq(
  "attribute",
  "*" // returns all attributes in the index not just searchable attributes
))

Can be used in these methods:
search, setSettings, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, set_settings, browse, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, setSettings, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey search, set_settings, browse, search_for_facet_values, generate_secured_api_key, add_api_key, update_api_key search, setSettings, browse, searchForFacetValues searchAsync, setSettingsAsync, browseAsync, searchForFacetValues Search, SetSettings, Browse, SearchForFacetValues, GenerateSecuredApiKey, AddApiKey, UpdateApiKey Search, setSettings, browse, searchForFacetValues, generateSecuredApiKey, addApiKey, updateApiKey Search, SetSettings, Browse, SearchForFacetValues, GenerateSecuredAPIKey, AddAPIKey, UpdateAPIKey search, changeSettings, browse index, search into facet values, generateSecuredApiKey, add key, update key

About this parameter

List of attributes to highlight.


Usage notes:
  • Only string values can be highlighted. Numerics will be ignored.

  • If set to null, all searchable attributes are highlighted (see searchableAttributes).

  • The special value * may be used to highlight all attributes.


Impact on the response:
  • 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")
    )
);
dynamic settings = new JObject();
settings.attributesToHighlight = new JArray()
  .put("author")
  .put("title")
  .put("content")

index.SetSettings(settings);
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 highlighted 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("*")
    )
);
dynamic settings = new JObject();
settings.attributesToHighlight = new JArray()
  .put("*")

index.SetSettings(settings);
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"
    ))
  )
}

The Response Object

"_highlightResult":{
  "attribute1":{
    "value":"<b>q<\/b>uery",
    "matchLevel":"full",
    "fullyHighlighted":false,
    "matchedWords": [ "q" ]
  },
  ...
}
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