You use the cfsearch
tag to search an indexed collection. Searching a Verity collection is similar to a standard ColdFusion query: both use a dedicated ColdFusion tag that requires a name
attribute for their searches. The following table compares the two tags:
Note: You receive an error if you attempt to search a collection that has not been indexed.
The following are important attributes for the cfsearch
tag:
name
The name of the search query.
collection
The name of the collection(s) being searched. Use a fully qualified path for an external collection. Separate multiple collections with a comma; for example, collection = "sprocket_docs,CodeColl".
criteria
The search target (can be dynamic).
Each cfsearch
returns variables that provide the following information about the search:
RecordCount
The total number of records returned by the search.
CurrentRow
The current row of the record set being processed by cfoutput
.RecordsSearched
The total number of records in the index that were searched. If no records were returned in the search, this property returns a null value.Note: To use cfsearch
to search a Verity K2 Server collection, the collection
attribute must be the collection's unique alias name as defined in the k2server.ini and the external
attribute must be "No" (the default). For more detail, see Administering ColdFusion MX.
You can use search form and results pages similar to the following examples to search a collection.
<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>
Enter a search target word(s) in this form, which passes this as the variable criteria
to the action page, which displays the search results.
<html> <head> <title>Search Results</title> </head> <body> <cfsearch name = "codecoll_results" collection = "CodeColl" criteria = "#Form.Criteria#"> <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#</p> </cfoutput> </body> </html>
The following figure shows how the output appears:
Note: As part of the indexing process, Verity automatically produces a summary of every document file or every query record set that gets indexed. The default summary selects the best sentences, based on internal rules, up to a maximum of 500 characters. Every cfsearch
operation returns summary information by default. For more information on this topic, see "Using Verity Search Expressions".