Creating a Search Interface ColdFusion Help

After an index is created, you can create a search interfac. Searching is don t. sing the CF SEARCH tag, which executes a search against a Verity collection. The tag returns the result as a typical ColdFusion result set that can then be worked with by using standard tags such as CFOUTPUT and CFLOOP. You can use the CFSEARCH tag to search collections containing indexes of documents or indexes of query results.

Searching an Index’ of Documents

To use the CFSEARCHtag to search an index of documents, you need to use the following attributes:
NAME Name of the search query for later reference to the results.
COLLECTION Name of the collection to be searched. Multiple collections can be searched by providing the names as a comma-separated list.
TYPE Specifies the type criteria to use in the search. Possible values are  and Explicit. These will be discussed later in the section “Building a Search Query.”
CRITERIA Specifies the search expression.
MAXROWS Specifies the maximum number of results to return. This is useful when returning the results groups (for instance, 10 results at a time). The default is to return all results. This is an optional field.
STARTROW Specifies the row to be returned. This is useful in conjunction with MAXROWSwhen returning results in smaller groups. The default is row 1. This is and optional field.
By way of example, consider the following CFsEARCH tag:

This tag searches the collection collectionname for the word Test and returns results in the result set results.

Using the Results

Just what is returned in a result set by the CFSEARCHtag? For each item (file or query result row) found to match the criteria, the following four columns are returned:
URL The full URL path for the collection (including the return URL value if one was defined when creating the index). This will be an empty string for indexes of query
KEY The contents of the KEYattribute specified when defining the index. In the-case of an index of documents, this will contain the full local path to the file on the server (such as  :\html \ file . html). In the case of an index of a query result set, this will contain the value of the column specified with the KEYattribute of the CFINDEX tag.
TITLE The contents of the TITLE attribute specified when creating the index. In the case of an index of documents, this will contain the document title obtained from the document itself (for instance, the text between <TITLE> and </TITLE> in an HTML file). In the case of an index of a query result set, this will contain the value of the column specified with the TITLE attribute of the CFINDEX tag
SCORE A score indicating how relevant the document is to the search criteria. For example, the following template searches a collection for the word Test and displays the results in a table

Understanding the Varity Query Syntax

Using the Verity search engine allows for much more complicated searches than the simple ones seen in this chapter. Query expressions for s=arches can be built out of a rich set of operators.

A distinction exists between simple and explicit queries as specified by ,the TYPE attribute of the CFSEARCH tag. Syntactically, simple queries are just that: simple. Simple queries accept comma-delimited lists of strings and wildcard characters. Simple queries search for whole words, so a search for sea will find only those results containing the word sea and not other words such as search. Simple searches do provide wildcards, so you can search for sea= and retrieve resultscontaining search as well.

Nonetheless, simple queries do exhibit stemming properties. That is, a search for sea will find words derived from the word sea such as seas (as opposed to search, which contains the string sea but is not derived from the word sea). By providing a list of strings separated by commas, the comma is taken to imply logical OR. That is, a search for sea. ocean will find all results with either the word sea or the word ocean or both.

Without commas, a series of words is treated as a phrase, so searching for sea ocean will find all results with the exact phrase sea ocean in them. In addition, simple queries allow for the use of the basic Boolean operators AND, OR, and NOT in a query. For instance.

Using Wildcards

ColdFusion provides the following wildcard operators for use in queries;
? Matches any single alphanumeric character
* Matches zero or more alphanumeric characters
[] Matche~ one of the characters contained between the brackets
{} Matches all the patterns, separated by .commas, contained in the curly brackets
” When used inside square brackets, indicates that a match should be made for any character not contained in the brackets .
– When used inside square brackets, indicates a range of characters
For example, consider the following patterns and their matches, outlined.

Using Explicit Queries

Explicit queries are far more complex because each element of the query has to be explicitly stated. For instance, stemming is not done by default, and logical ORis not automatilly implied by a comma. Explicit queries are extremely powerful in the hands of a user who understands the principles of building fine-tuned, effective query expressions.

Generally, however, a search engine on an average Web site will not need to offer this type of fine-grained search capability. If it does, the developer of the search engine does not need to master the intricacies of the search syntax, but rather can direct users to help based on Allaire’s documentation of the subject. For that reason, we will just glance at the major features of explicit queries. Details of the syntax can be found in the Allaire documentation in Derelaping Web Applications with Coldi’usion in Chapter 11, “Indexing and Searching Data.’

The major features of explicit queries are as follows:
• Words are nut stemmed, A search for sea matches only the word sea.
• Special characters including commas, brackets, parentheses, and single quotation marks have special meanings. To search for those characters, you must use a backslash to escape them. The backslash itself must be escaped, so \ \ must be used to search for a backslash.
• All operators except the three Boolean operators must be surrounded by-left and right angle brackets (0). Similarly, to search for the word,or MOT, they must, be surrounded by double quotes or they will be treated as operators.

Posted on November 16, 2015 in Implementing a Search Engine

Share the Story

Back to Top
Share This