Skip to main content
Signature

Import

See this widget in action

Preview this widget and its behavior.

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

JavaScript

Options

container
string | HTMLElement
required
The CSS Selector or HTMLElement to insert the widget into.
templates
object
The templates to use for the widget.
JavaScript
cssClasses
object
The CSS classes you can override:
  • root. The root element of the widget.
  • text. The text element for explanation.
  • button. The toggle button element.
JavaScript

Templates

You can customize parts of a widget’s UI using the Templates API. Each template includes an html function, which you can use as a tagged template. This function safely renders templates as HTML strings and works directly in the browser—no build step required. For details, see Templating your UI.
The html function is available in InstantSearch.js version 4.46.0 or later.
button
string | function
The template used for displaying the toggle button.
text
string | function
The template used for displaying extra information.

HTML output

HTML

Customize the UI with connectRelevantSort

If you want to create your own UI of the relevantSort widget, you can use connectors. To use connectRelevantSort, you can import it with the declaration relevant to how you installed InstantSearch.js.
Then it’s a 3-step process:
JavaScript

Create a render function

This rendering function is called before the first search (init lifecycle step) and each time results come back from Algolia (render lifecycle step).
JavaScript

Render options

isVirtualReplica
boolean
Indicates whether the index is a virtual replica.
JavaScript
isRelevantSorted
boolean
Indicates whether the search result is relevantly sorted out.
JavaScript
canRefine
boolean
required
Indicates if search state can be refined.
JavaScript
refine
function
Sets relevancyStrictness.
JavaScript
widgetParams
object
All original widget options forwarded to the render function.
JavaScript

Create and instantiate the custom widget

First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:
  • Instance parameters. Predefined options that configure Algolia’s behavior.
  • Custom parameters. Parameters you define to make the widget reusable and adaptable.
Inside the renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript

Full example

Last modified on July 10, 2026