Can query rules handle such composed search terms

Hello there!

I am looking for the right algolia primitive to solve the following case:

My index is a lit of recipes with ingredients.

Let’s pick two particular ingredients:

  • tomate cerise
  • pomme de terre

If you use tomate cerise (cherry tomato) in your search you want:

1- Exact match tomate cerise
2- Then tomatoes recipes
3- You do not want cerise recipes

In Python, I clean my terms to detect such occurrences.

   if 'pomme' in search_terms and 'terre' not in search_terms:
        cleaned_search_terms.append('pomme -terre')
    elif 'pomme' in search_terms and 'terre' in search_terms:
        cleaned_search_terms.append("'pomme de terre'")
    elif 'tomate' in search_terms and 'cerise' in search_terms:
        cleaned_search_terms.append("'tomate cerise'")
    elif 'tomate' in search_terms and 'cerise' not in search_terms:
    elif 'cerise' in search_terms and 'tomate' not in search_terms:
        cleaned_search_terms.append("cerise -tomate")

Any other ways?

1 Like

Hey @greg,

Algolia offers some tools that can help you achieve some things that you are trying to do. We have Query rules that can be helpful to you.

For example you can do something like this for tomate cersie:

When the query contains “tomate” and “cerise”, we put “cerise” as an optional word, so we get the following results when typing “tomate cerise”:

You can do a lot of things with query rules, as you can change the query parameters for any specific query text.

Of course, sometimes if you want to do very specific custom things, doing it on the client side could be a solution as well, but if you can do it from the engine it would be better.

Great Thank you, doing that right away.

My Pleasure! Also, I’m reiterating that your way works as well and can be a potential solution :slight_smile: