User Guide

282 Chapter 15 Indexing and Searching Data
Indexing Query Results
The following sections describe the reasons and procedures for indexing the results
of database, LDAP, and pop queries.
Indexing database query results
The main advantage of performing searches against a Verity collection over using
cfquery alone is that the database is indexed in a form that provides faster access.
Use this technique instead of
cfquery in the following cases:
You want to index textual data. You can search Verity collections containing
textual data much more efficiently with
cfindex than by searching a database
with
cfquery.
You want to give your users access to data without interacting directly with the
data source itself.
You want to improve the speed of queries.
You want your end users to run queries but not update database tables.
Indexing the result set from a ColdFusion query involves an extra step not required
when you index documents. You must code the query and output parameters, and
then point the
cfindex tag at the result set from a cfquery, cfldap, or cfpop query.
To index a ColdFusion query:
1 Create a collection on the ColdFusion Administrator Verity Collections page.
2 Execute a query and output the data.
3 Populate the collection using the cfindex tag.
To populate a collection from a
cfquery you specify a key attribute, which
corresponds to the primary key of the data source table, and a
body attribute, the
column or columns that you want to search for the index. The following extract
shows only the cfquery and cfindex parts of the process.
<!--- Select the entire table --->
<cfquery name="Messages"
datasource="MyMail">
SELECT *
FROM Messages
</cfquery>
<!--- Output the result set --->
<cfoutput query="Messages">
#Message_ID#, #Subject#, #Title#, #MessageText#
</cfoutput>
<!--- Index the result set --->
<cfindex collection="DBIndex"
action="Update"
type="Custom"