Signature
About this widget
Thesnippet
function returns attributes in your search results in a shorter form (a snippet).
Snippeted attributes are also highlighted.
This function uses Algolia’s snippeting feature
in combination with the hits
or infiniteHits
widgets.
To determine which attributes should be snippeted,
first set them from the Algolia dashboard,
the CLI,
or with the API (using the attributesToSnippet
parameter):
JavaScript
attributesToSnippet
, you can also set the snippet’s size to a specific number of words (it defaults to 10).
For example, attributesToSnippet: ['description:5']
.
Examples
JavaScript
Options
The attribute of the record to snippet.
For deeply nested objects, specify a dot-separated value like
actor.bio
.JavaScript
Original
hit
object provided to the function.
The value is already bound to the function inside a string template,
so you don’t have to provide it. For this to work,
the provided object must have a _snippetResult[attribute].value
property.JavaScript
The name of the HTML element to wrap the snippeted parts of the string.
JavaScript
The HTML element that wraps the non-highlighted parts of the string.
JavaScript
The character between each item when the attribute to highlight is an array.
JavaScript
The CSS classes you can override:
root
. The component’s root element.highlighted
. The highlighted parts.nonHighlighted
. The non-highlighted parts.separator
. The separator elements between highlighted parts.
JavaScript
HTML output
HTML