How to get AND plus OR in search work in single search

Hi,
I have noticed that in algolia searches the search result is based on “AND” of search keyword ie, if I am searching “Premium Phone” then all results will be having Premium and Phone in it. Is it possible to include in the response, result of individual words - Premium and Phone.
So basically I want the response to return records having “Premium AND Phone” OR “Premium” OR “Phone”. Also I want the Premium and Phone results to rank higher than Premium or Phone.
Is this possible in Algolia?
Thanks.

You should be able to accomplish this by setting removeWordsIfNotResult to allOptional in your index configuration.

  • allOptional: When a query does not return any results, make a second attempt treating all words as optional. This is equivalent to transforming the implicit AND operator applied between query words to an OR.

Read more here:

Hi Chuck,

Thanks for your response. My requirement is to add the matches for OR after AND. Looks like allOptional is about returning result when there arent any matches for AND.
I think optionalWords is something that does exactly what I am looking for.
Thanks for guiding me to the right documentation.

1 Like