
489
DEVELOPING
COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Las
t
upda
te
d 8/5/2010
<html>
<head>
<title>Searching a collection</title>
</head>
<body>
<h2>Searching a collection</h2>
<form method="post" action="collection_search_action.cfm">
<p>Enter search term(s) in the box below. You can use AND, OR, NOT, and
parentheses. Surround an exact phrase with quotation marks.</p>
<p><input type="text" name="criteria" size="50" maxLength="50">
</p>
<input type="submit" value="Search">
</form>
</body>
</html>
2
Save the file as collection_search_form.cfm.
Enter search target words in this form, which ColdFusion passes as the variable
criteria
to the action page, which
displays the search results.
Create the results page
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#"
contextPassages = "1"
contextBytes = "300"
maxrows = "100">
<h2>Search Results</h2>
<cfoutput>
Your search returned #codecoll_results.RecordCount# file(s).
</cfoutput>
<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.
3
View collection_search_form.cfm in the web browser.