Fuzzy search is important. Not all your visitors are perfect spellers but they still want the results they were looking for. Take for example the word Brazil. It can be spelled with a ‘z’ (Brazil) and with an ‘s’ (Brasil). How is Solr going to pick up Brasil with an ‘s’ if our content authors have spelled it with a ‘z’? This is where fuzzy search comes in and saves the day.
Definition right off brother Google:
A fuzzy search is a process that locates web pages that are likely to be relevant to a search argument even when the argument does not exactly correspond to the desired information
Fuzzy directly in Solr
The actual fuzzy query is very simple, and there are two things you need to understand. There is the ~ which indicates that the match does not need to be strict. Then we have the optional sharpness which is a double, for example 0.7 represents 70% sharpness. The query itself would look like: title_s:colombia~0.7
Let’s play with the query and see what we get back for results. Using the screenshot below you can see we are searching against the country Colombia (because I just finished watching the Netflix show Narcos).
- Query 1: I am using a strict (no fuzzy) and I have incorrectly spelled Colombia with a ‘u’ (Columbia). Due to the strictness Solr didn’t find any matches.
- Query 2: We are performing the same search as the first query but are apply 70% sharpness to our fuzzy call and Solr was able to figure out that it was close enough.
- Query 3: Here I changed the spelling a bit, i fixed the ‘u’ to an ‘o’, but I removed the ‘m’ and the ‘i’. Using 70% sharpness Solr returned me zero results. Although, as shown below, reducing the sharpness to 50% it was able to find the correct document.
Implementing on the Sitecore side of things is also very easy. In your content query you just need to apply a .Like() where you pass in your term and the sharpness. Let’s take a look at a simple example!