Usage
Parameters
CSS selector or HTMLElement to insert the widget.
Templates to use for the widget.
CSS classes to add to the widget elements.
Learn more about Mintlify
Enter your email to receive updates about new features and product releases.
import instantsearch from 'instantsearch.js';
import { stats } from 'instantsearch.js/es/widgets';
const search = instantsearch({
indexName: 'instant_search',
searchClient
});
search.addWidgets([
stats({
container: '#stats'
})
]);
search.start();
Show properties
nbHits, nbSortedHits, areHitsSorted, nbPages, page, processingTimeMS, query, hitsPerPage, and boolean helpers: hasManyResults, hasNoResults, hasOneResult, hasNoSortedResults, hasOneSortedResults, hasManySortedResults.Default: Displays results count and processing time.stats({
container: '#stats',
templates: {
text({ nbHits, processingTimeMS, nbSortedHits, areHitsSorted }) {
return `Found ${nbHits.toLocaleString()} results in ${processingTimeMS}ms`;
}
}
});
stats({
container: '#stats',
templates: {
text(props) {
if (props.areHitsSorted) {
return `${props.nbSortedHits} relevant results (out of ${props.nbHits})`;
}
return `${props.nbHits} results`;
}
}
});
<div class="ais-Stats">
<span class="ais-Stats-text">1,000 results found in 2ms</span>
</div>