Documentation Index
Fetch the complete documentation index at: https://algolia.com/llms.txt
Use this file to discover all available pages before exploring further.
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. TherelevantSort 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
The CSS Selector or
HTMLElement to insert the widget into.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 anhtml 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.The template used for displaying the toggle button.
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.
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
Indicates whether the index is a virtual replica.
JavaScript
Indicates whether the search result is relevantly sorted out.
JavaScript
Indicates if search state can be refined.
JavaScript
Sets
relevancyStrictness.JavaScript
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.
renderFunction, both instance and custom parameters are accessible through connector.widgetParams.
JavaScript