User Guide

Table Of Contents
566 Chapter 24: Building a Search Interface
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.
To create a search results page providing alternative spelling suggestions:
1.
Create a ColdFusion page with the following content:
<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>
2.
Save the file as collection_search_action.cfm.
Note: This overwrites the previous ColdFusion example page.
3.
View collection_search_form.cfm in the web browser:
4.
Enter any misspelled target words and click Search.