Posted on 18/12/2020 14:05:11
Hi Nuno
Let me try to explain...: The synonyms are on the terms. If you have a field with the value "one two three four", when analyzed it becomes 4 terms "one", "two", "three", "four" and you can create synonyms on each value, i.e. "one" -> "uno".
If you do NOT analyze the field, you get one term "one two three four" and you can create a synonym on the entire term, i.e. "one two three four" -> "Four Numbers". You cannot create a synonym on "two three" -> "two numbers" in either case because "two three" is not a term in either situation.
The synonyms filter comes from this code: https://www.codeproject.com/Articles/32201/Lucene-Net-Custom-Synonym-Analyzer - and that filter is wrapped in an Analyzer that encapsulates other built-in tokenizers and filters. So first the string is tokenized etc - then the synonyms are applied.
What you are trying to do will require you to take another approach. Because you need the synonym filter to execute before any of the other tokenizers and filters are applied - you would have to do string replace on the original text input to do that. And it would still not work very well - because your synonym "two three" -> "two numbers" would, after being analyzed later in the process , become 2 terms, "two", "numbers". That might be what you want, but does not make much sense... Unless you replace a "two three" with "twonumbers"...
I hope this makes things a little more clear and give you an idea of how to achieve what you need.
BR Nicolau