Nowadays, every business is online and having a digital transformation. They all are making huge websites with multiple web pages. Users are also becoming tech-savvy as well as want quick results. This is why, the search function you have needs to be extremely brilliant and effective.
In this blog, we will look at an example of how you can get search results for singular and plural words in your Sitecore website.
Issue: When the user searches with any plural word on the Sitecore website, then it gives results only with the plural keyword. The result with a singular term does not appear. For example, if the user searches keyword “videos” then the website gives only results with advice, not “video” results.
Solution: In this kind of scenario, we have used the Humanizer reference for the keyword singularize and pluralize. Please follow the below steps.
1 ) Singularize(inputIsKnownToBePlural: false) – This function is used for getting singular word and keep the parameter as false because we don’t know whether the searched keyword is plural or singular, so just put it as false.
If the keyword is already singular, then this function gives the same word but if it is plural then it will return the singular word.
2) Pluralize(inputIsKnownToBeSingular: false) – This function is used for getting the plural word and keep the parameter as false because we don’t know the searched keyword is plural or singular, so just put it false.
If the keyword is singular, then this function gives plural word and if it is already plural then it will give the same result.
From Humanizer reference you can use multiple functions like Pascalize(), Camelize(), Underscore() etc as below:
Now you can use this result of the function as plural/singular keyword in your search query.
By following the above given steps, you can implement the search code in a way that the keywords will provide search results in both plural and singular word searches.
If you want to learn more about how to implement the Search code in Solr, you can click on this link: https://www.addact.net/how-to-implement-solr-search-code-in-sitecore