Synonym search not working when searching for phrase

Hi,
If I search for a phrase, when I have synonym enabled, it searches for the whole phrase, rather than an or search for each individual word.

 text: {
            query: "radio tower",
            path:{'wildcard': '*'},
            synonyms: 'synonymCollection'
          }

So the above will only bring anything containing the whole phrase.

Hey there! You spotted a tricky one. This is something we are aware of and hoping to add solutions to improve, but what you are experiencing is the expected behavior.

A short term fix for it is to use compound with two should clauses - one with the text query that uses synonyms, and another that doesn’t.

  compound: {
    should: [
      {
        text: {
          query: "radio tower",
          path: {
            "wildcard": "*"
          },
          synonyms: "synonymCollection"
        }
      },
      {
        text: {
          query: "radio tower",
          path: {
            "wildcard": "*"
          }
        }
      }
    ]
  }
}
1 Like

Hi Elle,
Thank you for the reply. The issue with this is I wont get back any of the synonym results. So if search for transmission tower, with transmission being a synonym for radio ,I will only get back results for radio tower, and not where radio is by itself in a field. Then on the second text query, I will get results back for tower as normal. So the synonym part will be useless. With standard search if have radio in one field and tower in another field, this results have a higher score. But with synonyms I cant do this.

This is still the case, right? So if I want to search for each word individually, while using synonyms, should I handle the synonyms in JavaScript code instead of directly Mongo Alas?