Inform users about the current result set with Instantsearch JS Stats widget

Raphael Terrier
InstructorRaphael Terrier
Share this video with your friends

Social Share Links

Send Tweet

The stats widget is used to display useful insights about the current results like the number of hits and the time taken to compute the results inside the engine.

Instructor: [00:00] When a user searches on our website or app, it's always good to provide instant feedback on what is going on. The stats widget adds a small layer of information about queries that are made. It's not a critical widget, but it does bring a bit of value without any configuration necessary.

[00:17] To add it, as always, we first create the container in the HTML page, giving it an ID of stats. Then, in the app.js config, the same process as for all widgets -- search.addWidget instantsearch.widgets. We want the stats widget. We provide it the container, the ID stats. Then we reload the page.

[00:40] Right below the search bar, we now have displayed the total number of hits for the current query and how much time it took for the server to process that query, in milliseconds.