Skip to main content

About this widget

Each search Response contains various metadata you might display in your search experience. The following information is available as a part of the Response:
  • hitsPerPage. Number of hits per page.
  • nbHits. Total number of hits.
  • nbPages. Total number of pages.
  • page. Current page.
  • processingTimeMS. Processing time of the request (in ms).
  • query. Query text that produced these results.

Examples

Dart
class SearchStats extends StatelessWidget {
  const SearchStats(this.responses, {super.key});

  final Stream<SearchResponse> responses;

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<SearchResponse>(
        stream: responses,
        builder: (context, snapshot) => Text(stats(snapshot.data)));
  }

  String stats(SearchResponse? response) {
    if (response == null) return '';
    final buffer = StringBuffer();
    if (!response.exhaustiveNbHits) buffer.write("~");
    buffer.write("${response.nbHits} hits ");
    buffer.write("in ${response.processingTimeMS} ms");
    return buffer.toString();
  }
}
I