InstantSearch provides the FacetListState as a state model,
which is an implementation of the FacetListView interface.
You need to connect FacetListState to the FacetListConnector or FacetListViewModel like any other FacetListView implementation.
Kotlin
class MyActivity : AppCompatActivity() { val searcher = HitsSearcher( applicationID = "YourApplicationID", apiKey = "YourSearchOnlyAPIKey", indexName = "YourIndexName" ) val facetListState = FacetListState() val facetList = FacetListConnector( searcher = searcher, filterState = FilterState(), attribute = "facetName", selectionMode = SelectionMode.Multiple ) val connections = ConnectionHandler(facetList) init { connections += facetList.connectView(facetListState) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // You can use the default `FacetListAdapter`, or implement your own UI component that implements the `FacetListView` interface. setContent { facetListState.items.forEach { selectableFacet -> FacetRow( // your own UI composable to display `SelectableItem<FacetHits>` selectableFacet = selectableFacet, onClick = { facet -> facetListState.onSelection?.invoke(facet) } ) } } searcher.searchAsync() } override fun onDestroy() { super.onDestroy() connections.disconnect() searcher.cancel() }}
How to sort facets. Must be one or more of the following values:
FacetSortCriterion.IsRefined
FacetSortCriterion.CountAscending
FacetSortCriterion.CountDescending
FacetSortCriterion.AlphabeticalAscending
FacetSortCriterion.AlphabeticalDescending
Kotlin
// Tie-breaking algorithm where refined values are shown first.// If refined values are tied, show the facets with the largest counts.// If counts are tied, show facets in alphabetical order.FacetListPresenterImpl(listOf(IsRefined, CountDescending, AlphabeticalAscending))