attributesToHighlight
'attributesToHighlight' => [
'attribute',
'*', // returns all attributes in the index not just searchable attributes
...
]
Can be used in these methods:
search,
setSettings,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
set_settings,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
setSettings,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
search,
set_settings,
search_for_facet_values,
generate_secured_api_key,
add_api_key,
update_api_key
search,
setSettings,
searchForFacetValues,
generateSecuredApiKey,
addAPIKey,
updateAPIKey
search,
setSettings,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
SetSettings,
SearchForFacetValues,
GenerateSecuredApiKey,
AddApiKey,
UpdateApiKey
Search,
setSettings,
searchForFacetValues,
generateSecuredApiKey,
addApiKey,
updateApiKey
Search,
SetSettings,
SearchForFacetValues,
GenerateSecuredAPIKey,
AddAPIKey,
UpdateAPIKey
search,
setSettings,
search into facet values,
generateSecuredApiKey,
add key,
update key
About this parameter
List of attributes to highlight.
Usage notes
- If not set, all searchable attributes are highlighted (see
searchableAttributes
). - The special value
*
may be used to highlight all attributes. - Pass an empty array (
[]
) to disable highlighting and remove the_highlightResult
object in API responses.
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 viahighlightPreTag
andhighlightPostTag
. -
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
1
2
3
4
5
6
7
$index->setSettings([
'attributesToHighlight' => [
"author",
"title",
"content"
]
]);
Make all attributes highlighted by default
1
2
3
4
5
$index->setSettings([
'attributesToHighlight' => [
"*"
]
]);
Override default list of attributes to highlight for the current search
1
2
3
4
5
6
$results = $index->search('query', [
'attributesToHighlight' => [
"title",
"content"
]
]);
The Response Object
1
2
3
4
5
6
7
8
9
"_highlightResult":{
"attribute1":{
"value":"<b>q<\/b>uery",
"matchLevel":"full",
"fullyHighlighted":false,
"matchedWords": [ "q" ]
},
...
}