I couldn't find a difference between these two settings in algoliasearch-client-js. Could you simply explain how, and more importantly why to use these settings?
Example would be great!
attributesToHighlight
allows to retrieve the full content of attributes with matched words highlighted using <em>
html tag.
attributesToSnippet
extracts the part of the attribute that contains the most matched words and highlight them.
For example if you indexed object is:
{ "question": "algolia search - attributes to highlight vs attributes to snippet"}
If you use attributesToHighlight
, your search will be similar to:
search("algolia se", {"attributesToHighlight": "question"})
You will receive an answer of this form:
{
"question": "algolia search - attributes to high:light vs attributes to snippet",
"_highlightResult": {
"question": {
"value": "<em>algolia</em> </em>se</em>arch - attributes to highlight vs attributes to snippet",
"matchLevel": "full",
"matchedWords": [
"algolia",
"se"
]
}
If you use attributesToSnippet
, your search will be similar to:
search("algolia se", {"attributesToSnippet": "question:2"})
You will receive an answer of this form:
{
"question": "algolia search - attributes to high:light vs attributes to snippet",
"_snippetResult": {
"question": {
"value": "<em>algolia</em> </em>se</em>arch",
"matchLevel": "full",
"matchedWords": [
"algolia",
"se"
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With