Have you ever misspelt your search term in Google but Google suggests you the right term anyways? I know I have been in that situation, many a times.
Wouldn’t you love your Apache Solr to disregard the spelling mistakes and search for the right term anyway too? That would be cool, isn’t it? Here’s how you configure Solr to do that.
So, for Eg: You wanted to disregard the spelling mistake for “the”. So even if you type “teh” or “thhe” you still want Solr to search for all the terms with “the”, you need to just follow the following three easy steps:-
STEP 1: Write down all the synonyms in comma separated .txt file say synonyms.txt
the, teh, thhe
STEP 2: Once that is done. You can use the filter SynonymFilterFactory at query time in schema.xml.
<filter class=”solr.SynonymFilterFactory” synonyms=”synonyms.txt” ignoreCase=”true” expand=”true”/>
STEP 3: Restart your Apache Solr server and now it would use all the words interchangeably.
Also, you could use this feature to search for similar meaning words. For Eg: If you would like have a term Television that is indexed but you also want to show this content if people search for TV, you could modify your synonyms.txt file to include the following synonyms
Television, TV
And voila, your search is intelligent enough to treat your queries Television and TV interchangeably!
This could be used for a variety of other cases too. For example: If a name is spelt in different ways, just list it all out and you could make your search just that much more intelligent!