Searching for content on the web has evolved from basic string based matches to a sophisticated array of approaches including keywords, stemming, synonyms, word order, regular expressions, weights and relevance. Users expect the highest ranking results to be the most relevant and 75% of users don’t go past the first page of results. All of these advanced techniques are great to find relevant content. But sometimes you need to find an exact phrase with the specific words in a specific order. Many search engines do this by wrapping quote marks around the “search term” to indicate an exact match search. Sitecore Search defaults to relevance based searches, but you can achieve exact match search with some configuration.
Understanding Sitecore Search
Let’s take a moment to remember a few concepts in Sitecore Search to understand the configuration better.
- Index Document – A single piece of indexed content such as a webpage, a word document, a pdf, etc.
- Attributes – The fields of an indexed document such as title, subtitle, url, content type, etc.
- Textual Relevance – Defines the attributes used to locate potential results.
- Weight – Defines a relative value for how important an attribute is within the textual relevance.
- Analyzers – Convert the original search query into a format that is optimized for search.
- Token – A chunk of the original search query, usually a single word or phrase that is often modified by the analyzer to include synonyms, remove stop words and reformat to the root word.
Sitecore Search has a number of predefined analyzers built in. Each analyzer processes the search query in different ways.
The default analyzer is the multi local standard analyzer. This analyzer modifies the search query by making it lower case, splitting the search query into single word tokens, finding the root of each word, applying synonyms, and removing punctuation. For this reason, it will not find an exact match. For that we need the keyword analyzer which leaves the search query in a single token without applying any modifications.
Configure Exact Match Search – Textual Relevance
In order to configure exact match search, we need to add the keyword analyzer to the textual relevance settings for the desired attribute, in this case the description.
Navigate to Admin/Domain Settings then click the feature configuration tab.
Edit the Textual Relevance section.
Add the keyword analyzer to the description attribute.
Make sure to save your changes then publish your domain settings for your changes to take effect.
Configure Exact Match Search – Widget Settings
Next we need to configure our search widget to use our textual relevance settings.
Navigate to a widget variation and click add rule.
Click the top icon on the left to set the site context. Add a context rule for Keyword and select the contains option. In the input box, type a single quote mark.
Click the bottom icon on the left to configure the settings. Click the tab for Textual Relevance and click the toggle to enable the configuration. Notice that the description field is listed twice, once for each analyzer. From here you can enable/disable each attribute/analyzer and set its relative weight. In this example, I’ve set the description-keyword to 3 and the name-multilocal to 1. This will do the exact match search only on the description attribute. You could include name-keyword analyzer to do an exact match on the name as well if that is desired.
Repeat the process to add or modify a second rule that uses the description-multilocal analyzer.
This rule will be the fallback if the search term does not include a quote.
Exact Match Search in Action
With this configuration in place, you can see the difference in the search results. In this example, I’ve searched for “proxy statements”.
When you include a quote mark in the search term, you only get results that have the exact phrase “proxy statements”. This search returns 12 results.
When you do not include the quote mark in the search term, you get results that include proxy, statements and statement. This search returns 68 results.
Source: Read MoreÂ