> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Stats

> Shows data about the performed search.

<div className="not-prose algolia-flavor-switcher">
  <div className="afs-dropdown">
    <div className="afs-trigger" role="button" tabIndex="0" aria-haspopup="listbox">
      <span className="afs-current">Android</span>

      <svg className="afs-chevron lucide lucide-chevron-down" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
        <path d="m6 9 6 6 6-6" />
      </svg>
    </div>

    <ul className="afs-menu" role="listbox">
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/stats/js"><span className="afs-option-name">JavaScript</span><span className="afs-option-lib">InstantSearch.js</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/stats/react"><span className="afs-option-name">React</span><span className="afs-option-lib">React InstantSearch</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/stats/vue"><span className="afs-option-name">Vue</span><span className="afs-option-lib">Vue InstantSearch</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/stats/ios"><span className="afs-option-name">iOS</span><span className="afs-option-lib">InstantSearch iOS</span></a></li>
      <li role="option" aria-selected="true"><a className="afs-option is-current" href="/doc/api-reference/widgets/stats/android"><span className="afs-option-name">Android</span><span className="afs-option-lib">InstantSearch Android</span></a></li>
      <li role="option" aria-selected="false"><a className="afs-option" href="/doc/api-reference/widgets/stats/flutter"><span className="afs-option-name">Flutter</span><span className="afs-option-lib">Algolia for Flutter</span></a></li>
    </ul>
  </div>
</div>

```kotlin Signature theme={"system"}
StatsConnector(
    searcher: HitsSearcher,
    searchResponse: SearchResponse
)
```

<Card title="Explore example code" icon="github" href="https://github.com/algolia/instantsearch-android/tree/master/examples/android">
  Browse the Stats example code on GitHub.
</Card>

## About this widget

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).
* `query`. Query text that produced these results.

See also: [Get started with imperative UI](/doc/guides/building-search-ui/getting-started/how-to/programmatically/android)

## Examples

```kotlin Kotlin icon=code theme={"system"}
class MyActivity : AppCompatActivity() {
    val searcher = HitsSearcher(
        applicationID = "YourApplicationID",
        apiKey = "YourSearchOnlyAPIKey",
        indexName = "YourIndexName"
    )
    val stats = StatsConnector(searcher)
    val connection = ConnectionHandler(stats)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val statsView = StatsTextView(statsA)
        connection += stats.connectView(statsView, StatsPresenterImpl())
        searcher.searchAsync()
    }

    override fun onDestroy() {
        super.onDestroy()
        searcher.cancel()
        connection.disconnect()
    }
}
```

### Low-level API

If you want to fully control the Stats components and connect them manually, use the following components:

* `Searcher`. The [`Searcher`](/doc/api-reference/widgets/instantsearch/android) that handles your searches.
* `StatsViewModel`. The logic applied to the stats.
* `StatsView`. The view that renders the stats.

```kotlin Kotlin icon=code theme={"system"}
class MyActivity : AppCompatActivity() {
    val searcher = HitsSearcher(
        applicationID = "YourApplicationID",
        apiKey = "YourSearchOnlyAPIKey",
        indexName = "YourIndexName"
    )
    val statsViewModel = StatsViewModel()
    val connection = ConnectionHandler()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val statsView = StatsTextView(statsA)
        connection += statsViewModel.connectSearcher(searcher)
        connection += statsViewModel.connectView(statsView)
        searcher.searchAsync()
    }

    override fun onDestroy() {
        super.onDestroy()
        searcher.cancel()
        connection.disconnect()
    }
}
```

### Compose UI

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 Kotlin icon=code theme={"system"}
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()
    }
}
```

## Parameters

<ParamField body="searcher" type="HitsSearcher" required>
  The [`Searcher`](/doc/api-reference/widgets/instantsearch/android) that handles your searches.
</ParamField>

<ParamField body="searchResponse" type="SearchResponse">
  The initial search response to render.
</ParamField>

## View

<ParamField body="view" required>
  The view that renders the stats.
</ParamField>

<ParamField body="presenter" type="StatsPresenter<T>" required>
  The presenter that defines the way we want to display stats, taking as input a `Response` and returning a `T`.

  ```kotlin Kotlin icon=code theme={"system"}
  val view = StatsTextViewSpanned(statsB)
  val presenter: StatsPresenter<String> = StatsPresenterImpl() // or your own `StatsPresenter` implementation
  statsConnector.connectView(view, presenter)
  ```
</ParamField>
