Stats connector provides the logic to build a custom widget that will displays search statistics (hits number and processing time).
const search= instantsearch(/* parameters */);
const makeStats= instantsearch.connectors.connectStats(
function renderFn(
renderOpts: StatsRenderingOptions,
isFirstRendering: boolean) {
// render the custom Stats widget
}
);
const customStats = makeStats(instanceOpts: undefined);
search.addWidget(customStats);
number
The maximum number of hits per page returned by Algolia.
number
The number of hits in the result set.
number
The number of pages computed for the result set.
number
The current page.
number
The time taken to compute the results inside the Algolia engine.
string
The query used for the current search.
object
All original CustomStatsWidgetOptions
forwarded to the renderFn
.
// custom `renderFn` to render the custom Stats widget
function renderFn(StatsRenderingOptions, isFirstRendering) {
if (isFirstRendering) return;
StatsRenderingOptions.widgetParams.containerNode
.html(StatsRenderingOptions.nbHits + ' results found in ' + StatsRenderingOptions.processingTimeMS);
}
// connect `renderFn` to Stats logic
var customStatsWidget = instantsearch.connectors.connectStats(renderFn);
// mount widget on the page
search.addWidget(
customStatsWidget({
containerNode: $('#custom-stats-container'),
})
);
Can't find what you are looking for? Open an issue, we'll get back to you.