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

# Clear Filters

> Lets users reset all applied search refinements.

```kotlin Signature theme={"system"}
FilterClearConnector(
    filterState: FilterState,
    groupIDs: List<FilterGroupID>,
    mode: ClearMode,
    viewModel: FilterClearViewModel
)
```

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

## About this widget

`ClearFilters` lets users clear all refinements that are currently active within the given `FilterState`.

To add `ClearFilters` to your search experience, use these components:

* `FilterClearViewModel`. The logic for clearing refinements in the `FilterState`.
* `FilterState`. The current state of the filters.
* `FilterClearView`. The view that renders the clear filter UI.

## Examples

```kotlin Kotlin icon=code theme={"system"}
class MyActivity : AppCompatActivity() {
    val searcher = HitsSearcher(
        applicationID = "YourApplicationID",
        apiKey = "YourSearchOnlyAPIKey",
        indexName = "YourIndexName"
    )
    val color = "color"
    val category = "category"
    val groupColor = groupOr(color)
    val groupCategory = groupOr(category)
    val filters = filters {
        group(groupColor) {
            facet(color, "red")
            facet(color, "green")
        }
        group(groupCategory) {
            facet(category, "shoe")
        }
    }
    val filterState = FilterState(filters)
    val clearAll = FilterClearConnector(filterState = filterState)
    val clearSpecified = FilterClearConnector(
        filterState = filterState,
        groupIDs = listOf(groupColor),
        mode = ClearMode.Specified
    )
    val clearExcept = FilterClearConnector(
        filterState = filterState,
        groupIDs = listOf(groupColor),
        mode = ClearMode.Except
    )
    val connection = ConnectionHandler(
        clearSpecified, clearExcept, searcher.connectFilterState(filterState)
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        connection += clearAll.connectView(FilterClearViewImpl(filtersClearAll))
        connection += clearSpecified.connectView(FilterClearViewImpl(buttonClearSpecified))
        connection += clearExcept.connectView(FilterClearViewImpl(buttonClearExcept))
        searcher.searchAsync()
    }

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

### Compose UI

InstantSearch provides the `FilterClear` as a state model,
which is an implementation of the `FilterClearView` interface.
You need to connect `FilterClear` to the `FilterClearConnector` or `FilterClearViewModel` like any other `FilterClearView` implementation.

```kotlin Kotlin icon=code theme={"system"}
class MyActivity : AppCompatActivity() {
    val searcher = HitsSearcher(
        applicationID = "YourApplicationID",
        apiKey = "YourSearchOnlyAPIKey",
        indexName = "YourIndexName"
    )
    val color = "color"
    val category = "category"
    val groupColor = groupOr(color)
    val groupCategory = groupOr(category)
    val filters = filters {
        group(groupColor) {
            facet(color, "red")
            facet(color, "green")
        }
        group(groupCategory) {
            facet(category, "shoe")
        }
    }
    val filterState = FilterState()
    val filterClear = FilterClear()
    val clearAll = FilterClearConnector(filterState = filterState)
    val connections = ConnectionHandler(clearAll)

    init {
        connections += searcher.connectFilterState(filterState)
        connections += clearAll.connectView(filterClear)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyClearButton(clearAll) // your own composable to trigger filter clear
        }
        searcher.searchAsync()
    }

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

## Parameters

<ParamField body="filterState" type="FilterState" required>
  The [`FilterState`](/doc/api-reference/widgets/filter-state/android) that will hold your filters.
</ParamField>

<ParamField body="groupIDs" type="List<FilterGroupID>" post={["default: listOf()"]}>
  The group IDs of filters to clear.
  All filters will be cleared if unspecified.
</ParamField>

<ParamField body="mode" type="ClearMode" post={["default: ClearMode.Specified"]}>
  Whether we should clear the `Specified` filters or all filters `Except` them.
</ParamField>

<ParamField body="viewModel" type="FilterClearViewModel" post={["default: FilterClearViewModel()"]}>
  The logic for clearing refinements in the FilterState.
</ParamField>

## View

<ParamField body="view" type="FilterClearView" required>
  The view that renders the clear filter UI.

  ```kotlin Kotlin icon=code theme={"system"}
  val view = FilterClearViewImpl(myButton) // using your own Android view
  filterClearConnector.connectView(view)
  ```
</ParamField>
