iOS
Signature
Explore example code
Browse the Refinement List example code on GitHub.
About this widget
RefinementList is a filtering view that displays facets
and lets users refine the search results by filtering on specific values.
Requirements
Theattribute provided to the widget must be in attributes for faceting,
either on the dashboard or using the attributesForFaceting parameter with the API.
Examples
Instantiate aFacetListConnector and launch an initial search on its searcher.
Swift
Parameters
The
FilterState that holds your filters.The attribute to filter.
Whether a user can select
.single or .multiple values.If specified, the default facet value(s) to apply.
Whether you apply an
the filter sent to Algolia will be
and or or behavior to the facets in the filterState.For example, if you select color as the attribute and an or behavior,the filter sent to Algolia will be
color:red OR color:green.Use filters or facet filters for more complex result refinement.Filter group name.
Controller interfacing with a concrete facet list view.
Presenter defining how a facet appears in the controller.
Presenter
How to sort facets. Must be one or more of the following values:
.count(order: .descending).count(order: .ascending).alphabetical(order: .descending).alphabetical(order: .ascending).isRefined
Swift
The number of facet values to retrieve.
Swift
Whether to show facets with a facet count of 0.
Swift
Low-level API
If you want to fully control theRefinementList components and connect them manually, you can use the following components:
Searcher. TheSearcherthat handles your searches.FilterState. The current state of the filters.FacetListInteractor. The logic applied to the facets.FacetListController. The controller that interfaces with a concrete facet list view.FacetListPresenter. Optional. The presenter that controls the sorting and other settings of the facet list view.
Swift
Customizing your view
The controllers provided by default, like theFacetListTableViewController work well when you want to use native UIKit 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 FacetListController protocol.
Protocol
var onClick: ((Facet) -> Void)?:
Closure to call when a new facet is clicked.
func setSelectableItems(selectableItems: [SelectableItem<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 you want ti reload the list view.
Implementation example
Swift
SwiftUI
InstantSearch provides theFacetList SwiftUI view which you can embed in your views.
It uses FacetListObservableController as a data model,
which is an implementation of the FacetListController protocol adapted for usage with SwiftUI.
FacetListObservableController must be connected to the FacetListConnector or FacetListInteractor,
like any other FacetListController implementation.
You can define the appearance of the view representing a single facet and its selection state
or use the FacetRow view provided by InstantSearch.
Swift
FacetListObservableController as a data model.
It provides facets and selections properties along with convenient toggle and isSelected functions to streamline the design process of your custom SwiftUI view.