Before you begin
This tutorial requires InstantSearch.js.Implementation guide
This guide provides two implementation options for visual facets: you can either add the visual facet to your records or map the visual facets to your frontend.Add visual facets to your records
Add visual facets to your records
One way of implementing visual facets is by embedding the information you’re trying to display directly in your facet names.Set the facet attributes of all your records with the following pattern:If you’re creating a new index, use the If you’re updating an existing index, you can use the In the
If you’re doing this on an existing Algolia ,
you must update all your .
- The visual information (in this case, the URL of the image or the color code),
||as a separator,- The regular facet value.
JSON
saveObjects method with the just-mentioned facet values:partialUpdateObjects method.You also need to set the facet attributes as attributesForFaceting:refinementList widget of your InstantSearch implementation,
split your facet values on || to display the visual and attribute values.JavaScript
Map the visual facets to your frontend
Map the visual facets to your frontend
You can implement visual facets by adding a mapping directly in your frontend app. This solution requires that you use a consistent naming scheme for your images and facet names.First, create your mapping functions.The following function takes the facet label of an image and returns the image with the The following function takes a color facet and returns either the color or “transparent” if nothing was passed. Again, this is a rudimentary implementation: it doesn’t return the hexadecimal color code but instead requires your facets to use valid CSS color keywords.In your
.jpeg file extension tacked on. This is a rudimentary implementation: it requires your facets to use consistent image names.JavaScript
JavaScript
refinementList widget, use your mapping functions to transform each facet.JavaScript