Skip to main content
Signature

Explore example code

Browse the RelevantSort example code on GitHub.

About this widget

Virtual indices let you use relevant sort, a sorting mechanism that favors relevancy over the attribute you’re sorting on. The relevantSort widget displays the current search mode when searching in a virtual replica index, and allows users to switch between relevant and regular sorting, which is more exhaustive but can return less relevant results.

Examples

Instantiate a RelevantSortConnector.
Swift

Parameters

searcher
HitsSearcher
required
The Searcher that handles your searches.
interactor
RelevantSortInteractor
required
default: .init()
The logic to toggle relevant Sort.
controller
RelevantSortController
default: nil
Controller that presents and can toggle the Relevant Sort priority state.
presenter
RelevantSortPresenter<Output> | RelevantSortTextualPresenter
required
default: DefaultPresenter.RelevantSort.present
Presenter transforming the Relevant sort priority state to its representation for a controller.

Presenter

RelevantSort Presenter
RelevantSortPresenter<Output> | RelevantSortTextualPresenter
default:"DefaultPresenter.RelevantSort.present"
required
Presenter transforming the relevant sort priority state to its representation for a controller. Default presenter transforms relevant sort priority to RelevantSortTextualRepresentation? providing a tuple of string constants in English.
Swift

Low-level API

If you want to fully control the RelevantSort components and connect them manually, you can use the following components:
  • Searcher. The Searcher that handles your searches.
  • RelevantSortInteractor. Relevant sort priority toggling logic.
  • RelevantSortController. The controller that presents and toggles the Relevant sort priority state.
  • RelevantSortPresenter<Output>. Optional. Generic presenter transforming the Relevant Sort priority state to its representation for a controller.
Swift

Customizing your view

The controllers provided by default, like the ButtonRelevantSortController work well when you want to use native UIKit with their default behavior like a UIButton. If you want to use another component, 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 RelevantSortController protocol.

Protocol

func setItem(_ item: RelevantSortTextualRepresentation?) Function called when a new array of indices is defined. var didToggle: (() -> Void)? { get set } Closure triggered by the controller when the toggle happens (for example, toggle button clicked or switch control state changed)

Example

Swift

SwiftUI

InstantSearch provides the RelevantSortObservableController data model, which is an implementation of the RelevantSortController protocol adapted for usage with SwiftUI. RelevantSortObservableController must be connected to the RelevantSortConnector or RelevantSortInteractor like any other RelevantSortController implementation. The example of the SwiftUI view presenting the relevant sort state.
Swift
If you prefer to create a custom SwiftUI view that presents each , use the RelevantSortObservableController as a data model. It provides the state property along with the toggle function to streamline the design process of your custom SwiftUI view.
Last modified on July 10, 2026