Whether you apply an 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.
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
// 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.facetListPresenter = FacetListPresenter( sortBy: [.isRefined, .count(order: .descending), .alphabetical(order: .ascending)] )
The controllers provided by default,
like the FacetListTableViewController 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.
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.
InstantSearch provides the FacetList 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
struct ContentView: View { @ObservedObject var facetListController: FacetListObservableController var body: some View { FacetList(facetListController) { facet, isSelected in // Use the implementation provided by InstantSearch // FacetRow(facet: facet, isSelected: isSelected) // Or declare a custom single facet view HStack { Text(facet.value) Spacer() if isSelected { Image(systemName: "checkmark") .foregroundColor(.accentColor) } } .contentShape(Rectangle()) .frame(idealHeight: 44) .padding(.horizontal, 5) } }}
If you prefer to create a custom SwiftUI view that presents the list of facets,
you can directly use the 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.