What if you want to provide an alternative query if the number of search results returned by cfsearch is less than 10? This could help users who may have misspelled search terms. By setting the suggestions attribute in the cfsearch tag, you can now easily add a line at the top of the search results, suggesting an alternative search that the user can execute just by clicking the link you provide:
<cfsearch suggestions="10"
status="info"
collection="mycol"
criteria="#Form.query#">
<cfif info.FOUND LT 10>
Did you mean: <a href="search.cfm?query=#info.SuggestedQuery#>#info.SuggestedQuery#</a>
</cfif>
A nice feature for any application that provides search is to allow users to narrow down searches by searching only within the results of a previous search. By specifying the PreviousCriteria attribute in the cfsearch tag, ColdFusion limits the documents searched to only those returned from the last search. If the first search had 100 hits, the second search only searches those 100 documents for the criteria specified in the second search.
<cfif bSearchWithinResultsChecked>
<cfsearch collection="mycol"
criteria="#FORM.search#"
previousCriteria="#FORM.oldSearch#">
</cfif>
A standard feature of search sites, such as Google, is for the search results to contain snippets of the documents that contain the search terms. The cfsearch tag returns this information in the context column. The default value highlights the terms in bold, but you can provide attributes for the cfsearch tag to insert any string (HTML or otherwise) before and after the search terms. In addition, you can control both the number of passages (sentences) and the number of bytes (characters) that the search returns.
The following example specifies that the cfsearch tag should return three sentences, and not more that 1000 bytes, with the search terms in italics:
<cfsearch collection="mycol"
name="results"
criteria="mysearch keywords"
ContextHighlightBegin="<i>"
ContextHighlightEnd="</i>"
ContextPassages="3"
ContextBytes="1000">
<cfoutput Query="results">
Result context: #context#<br>
</cfoutput>