Skip to main content
The Stats connector provides the logic to build a custom widget that displays search statistics (hits number and processing time).

Usage

import { connectStats } from 'instantsearch.js/es/connectors';

const customStats = connectStats(
  (renderOptions, isFirstRender) => {
    const { nbHits, processingTimeMS, query, widgetParams } = renderOptions;
    const { container } = widgetParams;
    
    container.innerHTML = `
      <div>
        <strong>${nbHits.toLocaleString()}</strong> results found
        ${query ? ` for "<em>${query}</em>"` : ''}
        in <strong>${processingTimeMS}ms</strong>
      </div>
    `;
  }
);

search.addWidgets([
  customStats({
    container: document.querySelector('#stats'),
  }),
]);

Connector Options

This connector has no specific options.

Render Options

nbHits
number
The number of hits in the result set.
nbSortedHits
number
The number of sorted hits in the result set (when using Relevant sort).
areHitsSorted
boolean
Indicates whether the index is currently using Relevant sort and is displaying only sorted hits.
nbPages
number
The number of pages computed for the result set.
page
number
The current page.
hitsPerPage
number
The maximum number of hits per page returned by Algolia.
processingTimeMS
number
The time taken to compute the results inside the Algolia engine.
query
string
The query used for the current search.
widgetParams
object
The options passed to the connector.