SearfForFacetValue highlight bug

Hi, I implemented a refinementList widget using instantsearch.js, but when searching for facet values the response is returning malformed highlighted results:


The result item code is this:

<div class="ais-refinement-list--item">
	<label class="ais-refinement-list--label">
	  <input class="ais-refinement-list--checkbox" value="Colombia" type="checkbox">
	  <span class="ais-refinement-list--count">21</span>

And the error seems to come frome the Api response call:

It’s impossible to locally fix these behaviour because there’s no template option for the sffv results.
Is ther another way to fix it? or it must be fixed by algolia’s team?

Thanks For your Help.


You should replace the safe highlighting by a html tag to highlight, the __ais-highlight__ is the beginning tag, __/ais-highlight__ the end tag.

see (among other places: vue-instantsearch/sanitize-results.js at 9edf62e8535b8337ea44b3c81e1beee2228564f1 · algolia/vue-instantsearch · GitHub)

Thanks haroen,

Indeed i could replace the safe highlighting usig the transformData function:

	container: '#countries',
	attributeName: 'country_name',
	operator: 'or',
	collapsible: true,
	limit: 10,
	searchForFacetValues: {
		placeholder: 'Search',
		templates: {
			noResults: 'No results'
	transformData: function (item) {
		var h=item.highlighted+"";
		h = h.replace(/__ais-highlight__/g,'<em>');
		h = h.replace(/__\/ais-highlight__/g,'</em>');
		return item;

Thanks again for your guide.

1 Like

Perfect, I’m opening an issue in the repository as well so we can get it fixed in the library

EDIT: SFFV in refinementList has invalid html for highlighting · Issue #2474 · algolia/instantsearch · GitHub

1 Like