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
Published 6 years ago
Updated 3 years ago

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.

egghead
egghead
~ a minute ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today