Each search Response contains various metadata that you might display in your search experience.The following information is available as a part of the Response:
hitsPerPage. Number of hits per page.
totalHitsCount. Total number of hits.
pagesCount. Total number of pages.
page. Current page.
processingTimeMS. Processing time of the search request (in ms).
serverTimeMS. Processing time of the complete request (in ms).
InstantSearch provides the StatsState as a state model,
which is an implementation of the StatsView interface.
You need to connect StatsState to the StatsConnector or StatsViewModel like any other StatsView implementation.
Kotlin
Report incorrect code
Copy
class MyActivity : AppCompatActivity() { val searcher = HitsSearcher( applicationID = "YourApplicationID", apiKey = "YourSearchOnlyAPIKey", indexName = "YourIndexName" ) val statsState = StatsTextState() val stats = StatsConnector(searcher) val connections = ConnectionHandler(stats) init { connections += stats.connectView(statsState, StatsPresenterImpl()) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { MyStats(statsState) // your own UI composable to display stats } searcher.searchAsync() } override fun onDestroy() { super.onDestroy() searcher.cancel() connections.disconnect() }}
The presenter that defines the way we want to display stats, taking as input a Response and returning a T.
Kotlin
Report incorrect code
Copy
val view = StatsTextViewSpanned(statsB)val presenter: StatsPresenter<String> = StatsPresenterImpl() // or your own `StatsPresenter` implementationstatsConnector.connectView(view, presenter)