Filter List (Facet)
About this widget
FilterList.Facet is a filtering view that displays any kind of facet filters and lets the user refine their search results by selecting them.
Compared to the RefinementList, which takes its values from the search response facets, this widget displays facet filters that you add yourself.
To add a filter list to your search experience, use these components:
Searcher: TheSearcherthat handles your searches.FilterState: The current state of the filters.FilterListViewModel.Facet: The logic applied to the facet filters.FilterListView.Facet: The view that will render the facet filters.FilterPresenter: Optional. The presenter to customize the display of the filters.
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class MyActivity : AppCompatActivity() {
val client = ClientSearch(
ApplicationID("YourApplicationID"),
APIKey("YourAPIKey")
)
val index = client.initIndex(IndexName("YourIndexName"))
val searcher = SearcherSingleIndex(index)
val filterState = FilterState()
val color = Attribute("color")
val filters = listOf(
Filter.Facet(color, "red"),
Filter.Facet(color, "green"),
Filter.Facet(color, "blue"),
Filter.Facet(color, "yellow"),
Filter.Facet(color, "black")
)
val viewModel = FilterListViewModel.Facet(filters)
val connection = ConnectionHandler()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val view: FilterListView.Facet = MyFilterListRecyclerViewAdapter()
connection += searcher.connectFilterState(filterState)
connection += viewModel.connectFilterState(filterState)
connection += viewModel.connectView(view)
searcher.searchAsync()
}
override fun onDestroy() {
super.onDestroy()
connection.disconnect()
searcher.cancel()
}
}
Parameters
searcher
|
type: Searcher
Required
The |
||
|
Copy
|
|||
filterState
|
type: FilterState
Required
The |
||
|
Copy
|
|||
facetListView
|
type: FilterListView.Facet
Required
The view that will render the facet filters. |
||
|
Copy
|
|||
attribute
|
type: Attribute
Required
The attribute to filter. |
||
|
Copy
|
|||
items
|
type: List<Filter.Facet>
default: listOf()
Required
The facet filters to display. |
||
|
Copy
|
|||
groupId.operator
|
type: FilterOperator
default: FilterOperator.And
Optional
Whether we apply an For example if we have an |
||
|
Copy
|
|||
selectionMode
|
type: SelectionMode
default: Multiple
Optional
Whether the list can have |
||
|
Copy
|
|||
Presenter
presenter
|
type: FilterPresenter
default: FilterPresenterImpl()
Optional
A presenter describing how to display a filter. |
||
|
Copy
|
|||