User Guide

Table Of Contents
Enhancing search results 569
Searching collections that contain categories
When searching data in a collection created with categories, you specify
category and
categoryTree. The values supplied to these attributes specify what category should be searched
for the specified search string (the
criteria attribute). The category attribute can contain a
comma separated list of categories to search. Both attributes can be specified at the same time.
<cfsearch collection="collectionName"
name="results"
maxrows = "100"
criteria="search keywords"
category="FAQ,Technote"
categoryTree="Docs/Tags">
Note: If
cfsearch is executed on a collection that was created without category information, an
exception is thrown.
To search collections that contain categories, you use the cfsearch tag, and create an application
page that searches within specified categories. The following example lets the user enter and
submit the name of the collection, the category in which to search, and the document tree
associated with the category through a form. By restricting the search in this way, the users are
better able to retrieve the documents that contain the information they are looking for. In
addition to searching with a specified category, this example also makes use of the
contextHighlight attribute, which highlights the returned search results.
<cfparam name="collection" default="test-pi">
<cfoutput>
<form action="#CGI.SCRIPT_NAME#" method="POST">
Collection Name: <input Type="text" Name="collection" value="#collection#">
<P>
Category: <input Type="text" Name="category" value=""><br>
CategoryTree: <input Type="text" Name="categoryTree" value=""><br>
<P>
Search: <input Type="text" Name="criteria">
<input Type="submit" Value="Search">
</form>
</cfoutput>
<cfif isdefined("Form.criteria")>
<cfoutput>Search results for: <b>#criteria#</b></cfoutput>
<br>
<cfsearch collection="#form.collection#"
category="#form.category#"
categoryTree="#form.categoryTree#"
name="sr"
status="s"
criteria="#form.criteria#"
contextPassages="3"
contextBytes="300"
contextHighlightBegin="<i><b>"
contextHighlightEnd="</b></i>"
maxrows="100">
<cfdump var="#s#">