Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

Get Search Results for Singular and Plural words in your Sitecore Website

May 16, 2023
Get Search Results for Singular and Plural words in your Sitecore Website
Keyur Garala
Keyur Garala
Sitecore Certified Solutions Architect
get-search-results-for-singular-and-plural-words-in-your-sitecore-website

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.

  • Open Manage NuGet packages from visual studio or we can also use project from git https://github.com/Humanizr/Humanizer get-search-results-for-singular-and-plural-words-in-your-sitecore-website-1
  • After adding NuGet add references into your .cs file and use function of humanizer. get-search-results-for-singular-and-plural-words-in-your-sitecore-website-2
Functions for use of plural and singular word:

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:

get-search-results-for-singular-and-plural-words-in-your-sitecore-website-3

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


YOU MAY ALSO LIKE