[PreSales] another searcheable attribut if the result of the first one is blank

Hi,
a index with Name, tags, description.
InstantSearch.

“Name” and “tag” are currently searchable attributes, “description” is not.
Is there a way to set “description” as a searchable attribut ONLY if there’s no results with “name” and “tag”?
Thks

Hello,

It’s not possible to configure your index to do that with only one query, but you can achieve the same result with two queries like this:

  1. Setting your searchableAttributes to ['Name', 'tag', 'description'] in your index
  2. Doing a query and adding restrictSearchableAttributes: ['Name', 'tag'] so it will only search in those two
  3. When receiving the results, checking if you have results or not. If you have, just display them, and if don’t go to 4.
  4. Send another query, this time with restrictSearchableAttributes: ['description'] so it will now only search in the last attribute
  5. Display the results

Note that restrictSearchableAttributes must be a subset of searchableAttributes, that’s why you still need to define the full list in your index settings.

thks for you’re fast and precise answer.