![]() ![]() ![]() |
The CFSEARCH tag provides users with a set of operators and modifiers to create sophisticated query expressions. We'll explore these options in detail below, but first let's take a look at getting a basic search application up and running.
To quickly create a search application for an existing collection, click the File > New command in ColdFusion Studio and select the Verity Wizard in the CFML tab of the New Document dialog. The wizard creates a set of application pages based on the entries you make in the wizard dialogs.
You can customize the search interface by adding instructional text for users and applying styles to the form pages.
The power of the CFSEARCH tag is in the control it gives you over the Verity search engine. The engine offers users a high degree of specificity in setting search parameters.
An operator represents logic to be applied to a search element. This logic defines the qualifications a document must meet to be retrieved. Operators are used to refine your search or to influence the results in other ways. For example, you could construct an HTML form for conducting searches. In the form, a user could perform a search for a single term: server. You can refine your search by limiting the search scope in a number of ways. Operators are available for limiting a query to a sentence or paragraph, and you can search words based on proximity. The following operator types are available:
Ordinarily, you use operators in explicit searches. They are used in the following manner:
"<operator>search_string"
Modifiers can be used with operators to further refine query expressions. You can specify case sensitivity in a query, or force the output to be ranked by relevancy. Modifiers include:
Conducting a basic search is very straightforward using the CFSEARCH tag. In the following example, a simple search for the word "database" is performed on a collection created from a directory of HTML files called "DOCS."
<CFSEARCH NAME="DocSearch" COLLECTION="DOCS" TYPE="Simple" CRITERIA="database">
You use the CFOUTPUT tag to present the results of your search to your user. The following example shows a fully defined URL:
<CFOUTPUT QUERY="DocSearch"> <A HREF="#DocSearch.url#"> #DocSearch.Title#</A><BR> </CFOUTPUT>
The DocSearch.Title variable presents the contents of the HTML TITLE tag. This facility gives you excellent indexing options for managing large numbers of HTML documents. With judicious use of the TITLE tag, you could offer excellent searching options to users.
Every search conducted with the CFSEARCH tag returns up to seven result columns you can reference in your CFOUTPUT:
You can use these result columns in standard CFML expressions, preceding the result column name with the name of the query:
#DocSearch.URL# #DocSearch.KEY# #DocSearch.TITLE# #DocSearch.SCORE#
As part of the indexing process, Verity automatically produces a summary of every document file or query result set. The default summarization selects the best sentences, based on internal rules, up to a maximum of 500 characters. Summarization information is returned by default with every CFSEARCH operation. For more information on this topic, see the Allaire Knowledge Base article, "Custom1, Custom2 and Summary Fields" (ID# 1081) on our Web site.
To access the summary, invoke the property in the following form:
#search_query.Summary#
For example, in a search operation where the value of the NAME attribute is "mysearch" the following CFML outputs the summary of the search results:
<CFOUTPUT QUERY="mysearch"> #Summary#<BR> </CFOUTPUT>
For information on an advanced summarization technique, see the Allaire Knowledge Base article, "Synchronizing information stored in Verity Collection Document Fields with Corresponding Data from a Database" (ID# 1161) on our Web site.
Three properties are generated for each CFSEARCH query that provide information about a particular query:
You can use CFSEARCH properties in much the same way you use other ColdFusion system variables. For example, you can easily determine how many records were returned in a search with the following code:
<CFOUTPUT> <P>Your search returned #queryname.RecordCount# records.</P> </CFOUTPUT> <--- Present a message to the user if no records are returned ---> <CFIF #cfuser.RecordCount# LTE 0> <CFOUTPUT> <P>Sorry no instances of "#Form.searchquery#" found.</P> </CFOUTPUT> <CFELSEIF #cfuser.RecordCount# GT 0> <CFOUTPUT QUERY="cfuser"> <A HREF="#cfuser.url#">#cfuser.Title#</A><BR> </CFOUTPUT> </CFIF>
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.