Signature
Explore example code
Browse the Filter List (Facet) example code on GitHub.
About this widget
FacetFiltersList is a filtering component that displays facet filters and lets users refine the 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.
Examples
Instantiate aFacetFilterListConnector and launch an initial search on its Searcher.
Swift
Parameters
[FacetFilter]
required
default: []
The facet filters to display.
SelectionMode
default: .multiple
Whether a user can select
.single or .multiple values.FilterState
required
The
FilterState that holds your filters.RefinementOperator
required
Whether we apply an
and or or behavior to the filters in the filterState.For example if we have an or behavior,
the filter sent to Algolia will be _tags:promo OR color:green.String
required
Filter group name.
FilterListTableController<Filter.Facet>
default: nil
Controller interfacing with a concrete filter list view.
Low-level API
If you want to fully control theFacetFilterList components and connect them manually, you can use the following components:
Searcher. TheSearcherthat handles your searches.FilterState. The current state of the filters.FacetFilterListInteractor. The logic applied to the facet filters.FilterListController. The view that will render the facet filters.
Swift
Customizing your view
The controllers provided by default, such asFilterListTableController,
work well when you want to use native UIKit components with their default behavior.
If you want to use another component such as a UICollectionView,
a third-party input view,
or you want to introduce some custom behavior to the already provided UIKit component,
you can create your own controller conforming to the FacetFilterListController protocol.
Protocol
var onClick: ((Filter.Facet) -> Void)?:
Closure to call when a filter is clicked.
func setSelectableItems(selectableItems: [SelectableItem<Filter.Facet>])
Function called when a new array of selectable facets is updated. This is the UI State of the refinement list.
func reload()
Function called when the list view requires a reload.
Implementation example
Swift
SwiftUI
InstantSearch provides theFilterList SwiftUI view which you can embed in your views.
It uses FilterListObservableController as a data model, which is an implementation of the SelectableListController protocol adapted for usage with SwiftUI.
FilterListObservableController must be connected to the FacetFilterListConnector or FacetFilterListInteractor like any other SelectableListController implementation.
You have to define the appearance of the view representing a single facet filter and its selection state.
Swift
FilterListObservableController<Filter.Facet> as a data model.
It provides filters and selections properties along with toggle and isSelected functions to streamline the design process of your custom SwiftUI view.