Sitecore Insiders
fuzzy search

Fuzzy Search on Sitecore

Fuzzy Search on Sitecore

There are many reasons to have a fuzzy search in your search engine, the user doesn’t always spell the correct word, escaping special characters, or simply because you only have the word in the plural in your content, without it no results will be given.

Testing the query

To test your query in Solr or Azure search use the tilde “~” symbol in front of the word and then the distance parameter, in this case, I will use “0.7”

Searching for the word “search” with a typo.

Solr

Integrating with SXA Search components

First, extend the class Sitecore.XA.Foundation.Search.Services.SearchService
Then override the method “ContentPredicate” and add the extension “Like” from Sitecore.ContentSearch.Linq

As tested in Solr query the approach is similar, the first parameter for the input and the second for the distance parameter.

Now we just have to patch our code

  <sitecore>
    <services>
      <register patch:instead="*[@serviceType='Sitecore.XA.Foundation.Search.Services.ISearchService, Sitecore.XA.Foundation.Search']"
                serviceType="Sitecore.XA.Foundation.Search.Services.ISearchService, Sitecore.XA.Foundation.Search"
                implementationType="[method namespace], [namespace]" lifetime="Singleton"/>
    </services>
  </sitecore>

And that’s how you have a fuzzy search!

Jorge Pimenta

Certified Sitecore Devoloper since 2017
Sitecore Hackathon 2019 winner in the Best Sitecore Experience Accelerator Module (Team Noesis)
Always seeking to do things more practical and smarter rather than harder.

Add comment