Many unsuccessful searches are the result of incorrectly spelled query terms. Verity can automatically suggest alternative spellings for misspelled queries using a dictionary that is dynamically built from the search index.
To implement alternative spelling suggestions, you use the cfsearch
tag's suggestions
attribute with an integer value. If the number of documents returned by the search is less than or equal to the value you specify, Verity provides alternative search term suggestions. In addition to using the suggestions
attribute, you may also use the cfif
tag to output the spelling suggestions, and a link through which to search on the suggested terms.
Note: Using alternative spelling suggestions incurs a small performance penalty. This occurs because the cfsearch
tag must also look up alternative spellings in addition to the specified search terms.
The following example specifies that if the number of search results returned is less than 5, an alternative search term--which is displayed using the cfif
tag--is displayed with a link that the user can click to activate the alternate search.
<html> <head> <title>Search Results</title> </head> <body> <cfsearch name = "codecoll_results" collection = "CodeColl" criteria = "#Form.Criteria#"> status = "info" suggestions="5" ContextPassages = "1" ContextBytes = "300" maxrows = "100"> <h2>Search Results</h2> <cfoutput> Your search returned #codecoll_results.RecordCount# file(s). </cfoutput> <cfif info.FOUND LTE 5 AND isDefined("info.SuggestedQuery)> Did you mean: <a href="search,cfm?query=#info.SuggestedQuery#>#info.SuggestedQuery#</a> </cfif> <cfoutput query="codecoll_results"> <p> File: <a href="#URL#">#Key#</a><br> Document Title (if any): #Title#<br> Score: #Score#<br> Summary: #Summary#<br> Highlighted Summary: #context#</p> </cfoutput> </body> </html>
Note: This overwrites the previous ColdFusion example page.