Search
Clear search
Close search
Google apps
Main menu

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"/>
           </font></span>
        <xsl:variable name="apps_param">
          <xsl:choose>
            <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>
            <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" />
            </xsl:when>
          </xsl:choose>
        </xsl:variable>
        <a ctype="spell"
          href="{$gsa_search_root_path_prefix}?q={/GSP/Spelling/Suggestion[1]/@qe}&amp;spell=1&amp;{$synonym_url}{$apps_param}">
          <xsl:value-of disable-output-escaping="yes" select="/GSP/Spelling/Suggestion[1]"/>
        </a>
        </p>
      </xsl:if>
    </xsl:template>​

    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
    not(contains(/GSP/Spelling/Suggestion[1]/@q,'selected_term3'))">

  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 article helpful?
How can we improve it?