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
Attributes to snippet, with an optional maximum word limit.
Usage notes
This parameter lets you only show part of an attribute in search results: a snippet
- The snippet length is 10 words .
- To apply snippets to all attributes, use
*
.
Impact on the response:
When snippets are enabled, each search result contains a _snippetResult
object, which includes:
value
(string): the snippet text, highlighted according to thehighlightPreTag
andhighlightPostTag
settings. The default indicator for a snippet is an ellipsis character: customize it withsnippetEllipsisText
.matchLevel
(string, can benone
,partial
, orfull
): shows how closely the attribute matched the search query.
Examples
Set default attributes to snippet
1
2
3
4
5
6
$index->setSettings([
'attributesToSnippet' => [
'content:80',
'description'
]
]);
Snippet all attributes by default
1
2
3
4
5
$index->setSettings([
'attributesToSnippet' => [
"*:80"
]
]);
Override default 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"
},
...
}