Skip to content

Instantly share code, notes, and snippets.

@rayrutjes
Last active July 5, 2016 13:45
Show Gist options
  • Save rayrutjes/5a5954ca9c27cdcb47cc2cfb91c8daea to your computer and use it in GitHub Desktop.
Save rayrutjes/5a5954ca9c27cdcb47cc2cfb91c8daea to your computer and use it in GitHub Desktop.
Show relevant attribute instantsearch.js helper
search.templatesConfig.helpers.relevantContent = function() {
var attributes = ['content', 'title6', 'title5', 'title4', 'title3', 'title2', 'title1'];
var attribute_name;
for ( var index in attributes ) {
attribute_name = attributes[ index ];
if ( this._highlightResult[ attribute_name ].matchedWords.length > 0 ) {
return this._snippetResult[ attribute_name ].value;
}
}
return this._snippetResult[ attributes[ 0 ] ].value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment