Before you begin
This guide assumes certain data and software requirements:- Algolia records enriched using image classification. It doesn’t cover the UI part of this UX. Specifically, you’ll need to add the ability for users to upload an image to your search box and display results accordingly.
- Access to an image recognition platform such as Google Cloud Vision API.
You can’t store images directly in Algolia.
Instead, store the image on a content delivery network (CDN) or web server and add the image URL to a field in your records.
When you retrieve a record from Algolia, use this URL to display the image in your app.
Image classification
1
Transform your images
Since Algolia searches for records using a textual This returns these labels:
query or set of query parameters,
you need to transform your image files into a set of query parameters with an image recognition platform.
Image recognition platforms such as Google Cloud Vision API take an image and return a set of classifications, “labels”, for it.Once your users have uploaded an image to use for search, you need to run the image through the same image recognition platform you used to enrich your records.
You can use the same function you used to classify images on your records:JavaScript
JavaScript
2
Turn classifications into an Algolia query
Once you’ve extracted classifications from an image, turn them into an Algolia query.
For this, you can send an empty query with classifications as
optionalFilters.
Optional filters boost results with matching values.To use classifications as optionalFilters,
you must declare the classification attributes in attributesForFaceting.
Take each classification and format it properly:JavaScript
In this example, image classifications are stored in the
label.descriptions nested attribute in each product. You should update the optionalFilters text according to your record format.3
Pass `optionalFilters` as a query time parameter
How you pass these If you’re using an API client,
you can pass it as a parameter in the
optionalFilters depends on your frontend implementation.
If you’re using InstantSearch,
use the configure widget:search method: