1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

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

    Raphael TerrierRaphael Terrier
    algoliaAlgolia

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss