SDK/Theme Update: Result Count in onUniversalSearch

We’ve added some new information to the onUniversalSearch hook in the SDK. Previously we just returned queryString and sectionsCount. Now, we also return resultsCountByVertical, consisting of a map of verticalKey to an object with the totalResultsCount of that vertical and the displayedResultsCount.

Here’s an example:

resultsCountByVertical:
  locations: { totalResultsCount: 820, displayedResultsCount: 10}
  healthcare-professionals: {totalResultsCount: 1, displayedResultsCount: 1}
  links: {totalResultsCount: 757, displayedResultsCount: 10}
  people: {totalResultsCount: 4, displayedResultsCount: 4}
  restaurant: {totalResultsCount: 1, displayedResultsCount: 1}

To use this in the theme, you’ll need to override your core.hbs file. Then, within the existing ANSWERS.init, you’ll have access to onUniversalSearch:

//find this in core.hbs 
ANSWERS.init({
      templateBundle: TemplateBundle.default,
      ...injectedConfig,
      ...userConfig,
      //example exposing available text in onUniversal Search            
      onUniversalSearch: function(searchParams) {
        console.log(searchParams)
      },
      onStateChange: (objParams, stringParams, replaceHistory) => {  … },
      onReady: () => { … }
    });

You can do the exact same thing with the onVerticalSearch hook described here.

1 Like