Modify XSLT to exclude selected words from "Did you mean..." spelling suggestions

Summary: Some correctly spelled search terms show incorrect or inappropriate "Did you mean..." suggestions.

Fix: Modify front-end XSLT code to hide "Did you mean..." suggestions for correctly spelled or inappropriate words.

Example: You would like to block all suggestions containing "paper."

Suggestion displayed for correctly spelled "newspaper" word:

Did you mean: news paper

Step1 Check spelling suggestion returned

To exclude selected words from "Did you mean..." spelling suggestions, perform the following steps:

  1. Open Search > Search Features > Front Ends.
  2. Next to the front end you want to modify, click Edit.
  3. Under XSLT Stylesheet Editor, click Edit underlying XSLT code.
  4. Find <xsl:template name="spelling">
  5. Modify the following "if" condition:

    <!-- **********************************************************************
     Spelling suggestions in result page (do not customize)
         ********************************************************************** -->
    <xsl:template name="spelling">
      <xsl:if test="/GSP/Spelling/Suggestion">
        <p><span class="p"><font color="{$spelling_text_color}">
             <xsl:value-of select="$spelling_text"/>
             <xsl:call-template name="nbsp"/>
        <xsl:variable name="apps_param">
            <xsl:when test="/GSP/PARAM[@name='exclude_apps']">
              <xsl:text disable-output-escaping='yes'>&amp;exclude_apps=</xsl:text>
              <xsl:value-of select="/GSP/PARAM[@name='exclude_apps']/@original_value" />
            <xsl:when test="/GSP/PARAM[@name='only_apps']">
              <xsl:text disable-output-escaping='yes'>&amp;only_apps=</xsl:text>
              <xsl:value-of select="/GSP/PARAM[@name='only_apps']/@original_value" />
        <a ctype="spell"
          <xsl:value-of disable-output-escaping="yes" select="/GSP/Spelling/Suggestion[1]"/>

    You need to add additional "and" condition to disable spelling suggestion for "paper":

    <xsl:if test="/GSP/Spelling/Suggestion and not(contains(/GSP/Spelling/Suggestion[1]/@q,'paper'))">

    That should filter and disable incorrect spelling suggestion. If you need to exclude multiple words, they should be add as follow:

    <xsl:if test="/GSP/Spelling/Suggestion and not(contains(/GSP/Spelling/Suggestion[1]/@q,'selected_term1') and
    not(contains(/GSP/Spelling/Suggestion[1]/@q,'selected_term2') and

  6. Click Save
  7. Verify that "Did you mean" does not display for filtered words:

Step 2 Verify suggestion blocked

Additional Information: You can disable "Did you mean..." suggestions completely. See "Did you mean" text has incorrect spelling for more information about disabling spelling suggestions.

Versions affected: 7.2, 7.4 releases

Was this helpful?
How can we improve it?