Highlighting
Hey guys,
In the original twitter typeahead there was the highlight option, with algolia's implementation we have to access suggestion._highlightResult..., but what if I'm using the plugin with my own ajax calls like I used to do with twitter typahead, instead of the Algolia service? Is there a highlighting solution I'm not aware of?
Hi @legshooter,
yes indeed we removed it because our API was already doing the highlight. But your use-case is definitely legit, I'll try to restore such a feature. In the meantime, you can probably hack a .replace(/\bQUERY_WORD/g, '<em>QUERY_WORD</em>') for every word of your query.
Hi @redox,
My workaround currently looks like this:
suggestion: function (suggestion) {
var query = $('.search').autocomplete('val');
var regExp = new RegExp('(' + query + ')', 'giu');
return suggestion.name.replace(regExp, '<span class="highlight">$1</span>');
},
Takes care of case in/sensitivity etc.
Eagerly waiting for the official patch.
Thanks a lot for the pro tip and quick response, and keep being awesome!
+1, also miss this feature from typeahead.
Thanks for getting back here, currently the workarou from @legshooter is the way to go
Just wanted to say I came here for this exact reason. Thanks @legshooter
Autocomplete v0 has been in low maintenance mode for a few years and we just released Autocomplete v1 so I'm closing this.
Resources