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">
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#"> <cfoutput> <p>Number of records in query: #sr.recordcount#</P> </cfoutput> <cfdump var="#sr#"> <cfoutput Query="sr"> Title: <i>#title#</i><br> URL: #url#<br> Score: #score#<br> <hr> #context#<br> <br> #summary#<br> <hr> </cfoutput> </cfif>
For more information on using the cfindex tag to create Verity collections with support for categories, see cfsearch in the CFML Reference.