
497
DEVELOPING
COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Las
t
upda
te
d 8/5/2010
Working with data returned from a query
Using Verity, you can search data returned by a query—such as a database recordset—as if it is a collection of
documents stored on your web server. Using Verity to search makes implementing a search interface much easier, as
well as letting users more easily find information contained in database files. A database can direct the indexing
process, by using different values for the
type
attribute of the
cfindex
tag. There are also several reasons and
procedures for indexing the results of database and other queries.
Recordsets and types of queries
When indexing recordsets generated from a query (using the
cfquery
, cfldap, or
cfpop
tag),
cfindex
creates indexes
based on the
type
attribute and its set value:
The
cfindex
tag treats all collections the same, whether they originate from a database recordset, or if they are a
collection of documents stored within your website’s root folder.
Indexing data returned by a query
Indexing the results of a query is like indexing physical files located on your website, with the added step that you must
write a query that retrieves the data to search. The following are the steps to perform a Verity search on recordsets
returned from a query:
1
Create a collection.
2
Write a query that retrieves the data you want to search, and generate a recordset.
3
Index the recordset using the
cfindex
tag.
The
cfindex
tag indexes the recordset as if it is a collection of documents in a folder within your website.
4
Search the collection.
The information returned from the collection includes the database key and other selected columns. You can then
use the information as-is, or use the key value to retrieve the entire row from the database table.
Use Verity to search databases in the following cases:
•
You want to perform full-text search on database data. You can search Verity collections that contain textual data
much more efficiently with a Verity search than using SQL to search database tables.
•
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 users to be able to execute queries, but not update database tables.
Unlike indexing documents stored on your web server, indexing information contained in a database requires an
additional step— first write a query (using the
cfquery
, cfldap, or
cfpop
tag) that retrieves the data you want to let
your users search. You then pass the information retrieved by the query to a
cfindex
tag, which indexes the data.
When indexing data with the
cfindex
tag, specify which column of the query represents the filename, which column
represents the document title, and which column (or columns) represents the document’s body (the information that
you want to make searchable).
Type
Attribute values
File
The
key
attribute is the name of a column in the query that contains a full filename (including path).
Path
The
key
attribute is the name of a column in the query that contains a directory pathname.
Custom
The
key
attribute specifies a column name that can contain anything you want. In this case, the
body
attribute is
required, and is a comma-delimited list of the names of the columns that contain the text data to be indexed.