Here is the solution you will find on the Internet: https://dzone.com/articles/solution-multi-term-synonyms
Also, my solution to this problem was domain specific. In my case, I was sure of my query lengths (i.e., Less than 200, or just 5-10 words).
I replaced the spaces with underscores in the synonym entry. Here is one of my synonyms entries:
"like_to":["love_to","loves_to","need_to","needs_to"]
Use KeywordTokenizerFactory to send a complete filter request
<tokenizer class="solr.KeywordTokenizerFactory"/>
Use ShingleFilterFactory to index / query all possible subphrases of size from minShingleSize and mazShingleSize .
<filter class="solr.ShingleFilterFactory" minShingleSize="2" outputUnigrams="true" maxShingleSize="3"/>
Then use PatternReplaceCharFilterFactory to replace spaces with underscores ( _ )
<charFilter class="solr.PatternReplaceCharFilterFactory" pattern="\\s+" replacement="_"/>
Use the synonym filter factory.
Example
Request: I love to travel
Tokens: I love, I love to, love to, love to travel, to travel, tavel
Replaced _ : I_love, I_love_to, love_to, love_to_travel, to_travel, tavel
A synonymous filter turns them into: I_love, I_love_to, like_to, love_to_travel, to_travel, tavel
Thus, he will eventually change the phrase love to to like to .
Hope this trick will help, although it requires expensive operations.
source share