BackUp LevelNext

Populating a Collection from a Query

Indexing the result set from a ColdFusion query involves an extra step not required when indexing documents. You need to code the query and output parameters, then point the CFINDEX tag at the result set from a CFQUERY, CFLDAP, or CFPOP query.

To index a ColdFusion query:

  1. Create the collection on the ColdFusion Administrator Verity page.
  2. Execute a query and output the data.
  3. Populate the collection using the CFINDEX tag.

Indexing database query results

To populate a collection from a CFQUERY you specify a KEY, which corresponds to the primary key of the data source, and the BODY, the column in which you want to conduct searches. The following extract shows only the CFQUERY and CFINDEX parts of the process.

<!--- Select the entire table --->
<CFQUERY NAME="Messages" 
    DATASOURCE="CF 4.0 Examples">
    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"
    BODY="MessageText"
    KEY="Message_ID"
    TITLE="Subject"
    QUERY="Messages">

This CFINDEX statement specifies the MessageText column as the core of the collection and names the table's primary key, the Message_ID column, as the KEY value. Note that the TITLE attribute names the Subject column. The TITLE attribute can be used to designate an output parameter.

Indexing multiple columns

To index more than one column in a collection, enter a comma-separated list of column names for values of the BODY attribute, such as:

BODY=FirstName,LastName,Company

Custom fields

The CFINDEX tag supports two custom attributes, CUSTOM1 and CUSTOM2, that you can use to store data during an indexing operation. The query columns you specify as values for these attributes are returned in a CFSEARCH of the collection. For more information on this topic, see the Allaire Knowledge Base article, "Custom1, Custom2 and Summary Fields" (ID# 1081) on our Web site.

Advantages of indexing a data source

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:


BackUp LevelNext

allaire

AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.