Algolia doesn’t dynamically match on an index or another based on the semantic content of a query. It’s designed to search in one or several indices and retrieve the best matches based on its ranking formula. When querying multiple indices, result sets aren’t aggregated, they remain independent.
In your case, you’d like to first do some sort of semantic match to decide which one of your indices you should query. This is possible, but this logic needs to happen on your end. For example, when the user types “green shirt”, you’d need to have logic on the front end that intercepts the query, parses it, and decides what’s the most appropriate index, then forward the query to said index. As you can guess, such logic can be complex and lead to false positives.
From what I understand of your use case, you’d like to dynamically suggest filters on the front end based on the query. So, for example, if I type “leather shoes”, you’d recognize that I’m looking for shoes and not only switch to the right Algolia index, but also display appropriate refinement lists. Again, such logic can be complex, and if the user types something that doesn’t match anything, you have a difficult corner case to manage.
Instead, I would recommend keeping a single index, and typing your records. Here’s what it could look like:
"name": "Sportswear Outdoors T-Shirt",
"sizes": ["S", "M", "XL", "2XL"],
"colors": ["cargo", "black"],
"fabric": ["cotton", "rayon"],
"name": "Caesar Wooden Bed Frame",
"materials": ["Mahogany", "Stainless steel"],
This allows you to filter on
type whenever you know a user is looking for a specific kind of item, but you can fall back to the entire index when you don’t know.
In terms of UI, there are many ways to filter on a specific category. You can do “smart” filtering based on the query, but again this can be hard to do and isn’t necessarily transparent for the user. One way you could implement it is to do two searches when user type a query: a normal one in the index, and a search for facet values for each tokenized term in the
type attribute. Then, if you have matches, you could display the filter and let users select them or not.
Another, simpler approach which you can see on Amazon, they have a drop-down list next to the search box to select an existing category. You can use an InstantSearch refinementList to implement it.