> ## Documentation Index
> Fetch the complete documentation index at: https://www.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] [Explore example code](https://github.com/algolia/instantsearch-android/tree/master/examples/android)
>
> Browse the Clear Filters example code on GitHub.

## 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

**filterState** `FilterState` *required*

The [`FilterState`](https://www.algolia.com/doc/api-reference/widgets/filter-state/android) that will hold your filters.

**groupIDs** `List\<FilterGroupID\>`

The group IDs of filters to clear.
All filters will be cleared if unspecified.

**mode** `ClearMode`

Whether to clear the `Specified` filters or all filters `Except` them.

**viewModel** `FilterClearViewModel`

The logic for clearing refinements in the FilterState.

## View

**view** `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)
```
