If you’re using the deprecated
recommend-js
UI library,
see lookingSimilar
.Signature
Import
About this widget
Use thelookingSimilar
widget to display a list of similar-looking products based on the image URLs you referenced when setting up this Recommend model.
See also: Set up Algolia Recommend
Examples
JavaScript
With a carousel layout
Display thelookingSimilar
widget as a scrollable carousel.
JavaScript
Options
The CSS Selector or
HTMLElement
to insert the widget into.The list of object IDs for which to get recommendations.
If you specify multiple object IDs,
you’ll get a single set of aggregated results from the requests, ordered by their score.
Each
objectID
you pass in the array counts towards the number of requests in
your pricing plan. For example, if you
want recommendations for the array ["A", "B", "C"]
, you’ll consume three
requests from your quota, not one.JavaScript
The number of recommendations to retrieve.
Depending on the available recommendations and the other request parameters,
the actual number of items may be lower than that.
If
limit
isn’t provided or set to 0, all matching recommendations are returned.JavaScript
The threshold for the recommendations confidence score (between 0 and 100).
Only recommendations with a greater score are returned.
JavaScript
List of search parameters to send.
JavaScript
List of search parameters to send as additional filters when there aren’t enough recommendations.
JavaScript
Escapes HTML entities from recommendations string values.
JavaScript
The CSS classes you can override:
root
. The widget’s root element.emptyRoot
. The container element without results.title
. The widget’s title element.container
. The container of the list element.list
. The list of recommendations.item
. The list item.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.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 to use when there are no recommendations.
The template to use for the recommendations header.
This template receives the recommendations as well as the
cssClasses
object.The template to use for each recommendation.
This template receives an object containing a single record.
The template to use to wrap all items.InstantSearch.js provides an out-of-the-box carousel layout template with the following options:
cssClasses
:root
. The carousel’s root element.list
. The list of recommendations.item
. The list item.navigation
. The navigation controls.navigationPrevious
. The “Previous” navigation control.navigationNext
. The “Next” navigation control.
templates
:previous
. The content of the “Previous” navigation control.next
. The content of the “Next” navigation control.
HTML output
HTML
Customize the UI with connectLookingSimilar
If you want to create your own UI of the lookingSimilar
widget, you can use connectors.
To use connectLookingSimilar
, 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
Rendering options
The matched recommendations from the Algolia API.
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
Instance options
The list of object IDs for which to get recommendations.
If you specify multiple object IDs,
you’ll get a single set of aggregated results from the requests, ordered by their score.
Each
objectID
you pass in the array counts towards the number of requests in
your pricing plan. For example, if you
want recommendations for the array ["A", "B", "C"]
, you’ll consume three
requests from your quota, not one.JavaScript
The number of recommendations to retrieve.
Depending on the available recommendations and the other request parameters,
the actual number of items may be lower than that.
If
limit
isn’t provided or set to 0, all matching recommendations are returned.JavaScript
The threshold for the recommendations confidence score (between 0 and 100).
Only recommendations with a greater score are returned.
JavaScript
List of search parameters to send.
JavaScript
List of search parameters to send as additional filters when there aren’t enough recommendations.
JavaScript
Escapes HTML entities from recommendations string values.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript