View comments | RSS feed

cfsearch

Description

Searches Verity collections using ColdFusion or K2Server, whichever search engine a collection is registered by. (ColdFusion can also search collections that have not been registered, with the cfcollection tag.)

A collection must be created and indexed before this tag can return search results.

A collection can be created in these ways:

A collection can be registered with ColdFusion in the following ways:

A collection can be registered with K2Server by editing the k2server.ini file.

A collection can be indexed in the following ways:

For more information, see Developing ColdFusion MX Applications with CFML.

Category

Extensibility tags

Syntax

<cfsearch 
  name = "search_name"
  collection = "collection_name"
  type = "criteria"
  criteria = "search_expression"
  maxRows = "number"
  startRow = "row_number"
  language = "language">

See also

cfcollection, cfexecute, cfindex, cfobject, cfreport, cfwddx

History

New in ColdFusion MX: the The external attribute is deprecated. Do not use it in new applications. It might not work, and might cause an error, in later releases. (ColdFusion stores this information about each collection; it automatically detects whether a collection is internal or external.) This tag supports absolute (also known as fully qualified) collection pathnames and mapped collection names.

New in ColdFusion MX: ColdFusion can create collections, index query results and delete index keys.

New in ColdFusion MX: ColdFusion supports Verity operations on Acrobat PDF files.

New in ColdFusion MX: This tag can search multiple collections. In a multiple collection search, you cannot combine collections that are registered with K2Server and and registered in another way.

New in ColdFusion MX: This tag accepts collection names that include spaces.

New in ColdFusion MX: this tag supports Verity 2.6.1 and the LinguistX and ICU locales.

New in ColdFusion MX: This tag can throw the SEARCHENGINE exception.

Attributes

Attribute Req/Opt Default Description
name
Required


Name of the search query.
collection
Required

One or more path(s) and/or registered collection name(s).
For a registered collection, specify the collection name.
For an unregistered collection, specify an absolute path.
Registered names are listed in the ColdFusion Administrator, Verity Collections and Verity Server pages.
To specify multiple collections, use a comma delimiter. For example: "CFUSER, e:\collections\personnel
If you specify multiple collections, you cannot include a combination of collections that are registered by K2Server and registered by Verity.
type
Optional
simple
  • simple: STEM and MANY operators are implicitly used. See Developing ColdFusion MX Applications with CFML.
  • explicit: operators must be invoked explicitly
criteria
Optional

Search criteria. Follows the syntax rules of the type attribute. If you pass a mixed-case entry in this attribute, the search is case-sensitive. If you pass all uppercase or all lowercase, the search is case-insensitive. Follow Verity syntax and delimiter character rules; see Developing ColdFusion MX Applications with CFML.
maxRows
Optional
All
Maximum number of rows to return in query results. Use double or single quotation marks.
startRow
Optional
1
First row number to get.
language
Optional
english
For options, see "cfcollection". Requires the ColdFusion International Search Pack.

Usage

To permit application users to search Verity collections for non-standard strings, words or characters (for example, "AB23.45.67" or "--->") that would otherwise cause an error, you can create a text file that lists these elements and defines their formats for Verity. Name the file style.lex and put copies of the file in these directories:

Note:   To search for a character such as an angle bracket (< or >), you must use a criteria attribute value such as "&lt:" or "&lt:". The bracket characters are reserved in Verity, and using a backslash to escape the character (criteria="\<") does not work in this context. For more information, see Developing ColdFusion MX Applications with CFML.

Macromedia does not recommend using the cflock tag with this tag; Verity provides the locking function. Using the cflock tag slows search performance.

This tag returns a record set whose columns you can reference in a cfoutput tag. For example, the following code specifies a search for the exact terms "filming" or "filmed":

<cfsearch
name = "mySearch"
collection = "myCollection"
criteria = '<WILDCARD>`film{ing,ed}`'
type="explicit"
startrow=1>
<cfdump var = "#mySearch#>

In this example, the single quotation mark (') and backtick (`) characters are used as delimiters; for more information, see Developing ColdFusion MX Applications with CFML.

cfsearch result columns

Variable Description
url
Value of URLpath attribute in the cfindex tag used to populate a collection. If type = "custom", the value is always empty when you populate a collection.
key
Value of the attribute in the cfindex tag used to populate collection
title
Value of title attribute in cfindex operation used to populate the collection, including PDF and Office document titles. If title is not provided, the tag uses the cfindex title attribute value for each row.
score
Relevancy score of document based on search criteria
custom1, custom2
Value of custom fields in cfindex operation used to populate collection.
summary
Contents of automatic summary generated by cfindex.
Default: best three matching sentences, up to 500 characters.
recordCount
Number of records returned in record set
currentRow
Current row that cfoutput is processing
columnList
List of column names within record set
recordsSearched
Number of records searched

You can use query result columns in standard CFML expressions, preceding the result column name with the name of the query, as follows:

#DocSearch.url# 
#DocSearch.key#
#DocSearch.title#
#DocSearch.score#

Example

<!--- #1 (TYPE=SIMPLE) ----------------------------->
<cfsearch 
    name="name" 
    collection="snippets,syntax,snippets" 
    criteria="example" >
<p>
<cfoutput>Search Result total =  #name.RecordCount# </cfoutput><br>
<cfoutput>
    url=#name.url#<br>
    key=#name.key#<br>
    title=#name.title#<br>
    score=#name.score#<br>
    custom1=#name.custom1#<br>
    custom2=#name.custom2#<br>
    summary=#name.summary#<br>
    recordcount=#name.recordcount#<br>
    currentrow=#name.currentrow#<br>
    columnlist=#name.columnlist#<br>
    recordssearched=#name.recordssearched#<br>
</cfoutput>
<cfdump var = #name#>
<br>

<!--- #2 (TYPE=EXPLICIT) ----------------------------->
<cfsearch 
    name = "snippets"
    collection = "snippets"
    criteria = '<wildcard>`film{ing,ed}`'
    type="explicit"
    startrow=1>
<cfoutput 
    query="snippets">
    url=#url#<br>
    key=#key#<br>
    title=#title#<br>
    score=#score#<br>
    custom1=#custom1#<br>
    custom2=#custom2#<br>
    summary=#summary#<br>
    recordcount=#recordcount#<br>
    currentrow=#currentrow#<br>
    columnlist=#columnlist#<br>
    recordssearched=#recordssearched#<br>
</cfoutput>
<cfdump var = #snippets#> 
<br>

<!--- #3 (search by CF key) ----------------------------->
<cfsearch 
    name = "book"
    collection = "custom_book"
    criteria = "cf_key=bookid2">
<cfoutput>
    url=#book.url#<br>
    key=#book.key#<br>
    title=#book.titleE#<br>
    score=#book.score#<br>
    custom1=#book.custom1#<br>
    custom2=#book.custom2#<br>
    summary=#book.summary#<br>
    recordcount=#book.recordcount#<br>
    currentrow=#book.currentrow#<br>
    columnlist=#book.columnlist#<br>
    recordssearched=#book.recordssearched#<br>
</cfoutput>
<cfdump var = #book#> 
<br>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


carehart@systemanage said on Dec 30, 2002 at 8:16 AM :
Regarding the above statement:

New in ColdFusion MX: ColdFusion can create collections, index query results and delete index keys.

The ability to create collections isn't new in CFMX. What's meant by this? Certainly, CFSEARCH cannot create collections. As explained elsewhere on the page, the only way to create a collection in CFMX is with CFCOLLECTION or the CF Admin, and neither of those is new.

As for being able to "index query results" and "delete index keys", in case anyone was wondering (I had someone ask me), this is the ability to take the results of a CFSEARCH and index it with CFINDEX. If you try it in CF5, it fails, whereas in CFMX it does now seem to work.
No screen name said on Mar 29, 2004 at 5:00 PM :
It appears that there is a new behavior for cfmx 6.1. Under CF5,
<cfsearch name = "qrySearchHits"
collection = "#request.verity.colname#"
criteria = "#attributes.text#"
maxrows = "#wkMaxRows#"
startrow = "#attributes.StartRow#"
>
will return hits #26-50 if wkMaxRows==25 and attributes.StartRow==26. However, under cfmx 6.1, <cfsearch> will return zero hits with these values. Instead, one must use wkMaxRows==50 and attributes.StartRow==26 in order to get hits #26-50.

When migrating my code I changed the above to the following:
<cfsearch name = "qrySearchHits"
collection = "#request.verity.colname#"
criteria = "#attributes.text#"
maxrows = "#Evaluate(attributes.StartRow + wkMaxRows - 1)#"
startrow = "#attributes.StartRow#"
>

The documentation for "maxrows" would seem to indicate that this behavior is not intended for cfmx 6.1, and, indeed, a better name for "maxrows" under this behavior would be "lastrow".

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt3.htm