attributesToSnippet
[]
(no attribute is snippeted)
'attributesToSnippet' => [
'attribute',
'attribute2:number_of_words;', // limits the size of the snippet
...
]
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 snippet, with an optional maximum number of words to snippet.
Usage notes
- The number of words can be omitted, and defaults to
10
. - If not set, no attributes are snippeted.
- The special value
*
may be used to snippet all attributes.
Impact on the response:
-
When snippeting is enabled, each hit in the response will contain an additional
_snippetResult
object (provided that at least one of its attributes is snippeted) with the following fields:-
value
(string): Markup text with occurrences highlighted and optional ellipsis indicators. The tags used for highlighting are specified viahighlightPreTag
andhighlightPostTag
. The text used to indicate ellipsis is specified viasnippetEllipsisText
. -
matchLevel
(string, enum) = {none
|partial
|full
}: Indicates how well the attribute matched the search query.
-
Examples
Set default list of attributes to snippet
1
2
3
4
5
6
$index->setSettings([
'attributesToSnippet' => [
'content:80',
'description'
]
]);
Make all attributes highlighted by default
1
2
3
4
5
$index->setSettings([
'attributesToSnippet' => [
"*:80"
]
]);
Override default list of attributes to snippet for the current search
1
2
3
4
5
6
$results = $index->search('query', [
'attributesToSnippet' => [
"title",
"content:80"
]
]);
The Response Object
1
2
3
4
5
6
7
"_snippetResult":{
"attribute":{
"value":"to be or not to be that is ...",
"matchLevel":"full"
},
...
}