# CFSEARCH

Use the CFSEARCH tag to execute searches against data indexed in Verity collections. Collections can be created by calling the CFCOLLECTION tag, by using the ColdFusion Administrator, or through native Verity indexing tools. Collections are populated with data either with the CFINDEX tag, or externally, using native Verity indexing tools. Collections must be created and populated before any searches can be executed.

### Syntax

    <CFSEARCH NAME="search_name"
        COLLECTION="collection_name"
        TYPE="criteria"
        CRITERIA="search_expression"
        MAXROWS="number"
        STARTROW="row_number"
        EXTERNAL="Yes/No"
        LANGUAGE="language">

#### NAME

Required. A name for the search query.

#### COLLECTION

Required. Specifies the logical collection name that is the target of the search operation or an external collection with fully qualified path. Collection names are defined either through the CFCOLLECTION tag or in the ColdFusion Administrator, Verity page.

Multiple ColdFusion collections can be specified in a comma-separated list:

    COLLECTION="CFUSER, CFLANG"

If you are searching an external collection (EXTERNAL="Yes") specify the collection name, including fully qualified path:

    COLLECTION="e:\collections\personnel"

If multiple collections are specified in COLLECTION and EXTERNAL is Yes, the specified collections must all be externally generated. You cannot combine internal and external collections in the same search operation.

#### TYPE

Optional. Specifies the criteria type for the search. Valid entries are:

- SIMPLE -- By default the STEM and MANY operators are used.
- EXPLICIT -- All operators must be invoked explicitly.

#### CRITERIA

Optional. Specifies the criteria for the search following the syntactic rules specified by TYPE.

#### MAXROWS

Optional. Specifies the maximum number of entries for index queries. If omitted, all rows are returned.

#### STARTROW

Optional. Specifies the first row number to be retrieved. Default is 1.

#### EXTERNAL

Optional. Yes or No. Yes indicates that the collection you are searching was created outside of ColdFusion using native Verity indexing tools. The default is No.

#### LANGUAGE

Optional. To use the LANGUAGE attribute you must have the ColdFusion International Search Pack installed. Valid entries are:

- English (default)
- German
- Finnish
- French
- Danish
- Dutch
- Italian
- Norwegian
- Portuguese
- Spanish
- Swedish

### Usage

In the CRITERIA attribute, if you pass a mixed case entry (mixed upper and lower case), case sensitivity is applied to the search. If you pass all upper or all lower case, case insensitivity is assumed.

Every search conducted with the CFSEARCH tag returns, as part of the record set, a number of result columns you can reference in your CFOUTPUT:

- URL -- Returns the value of the URLPATH attribute defined in the CFINDEX tag used to populate the collection. This value is always empty when you populate the collection with CFINDEX when TYPE="Custom".
- KEY -- Returns the value of the KEY attribute defined in the CFINDEX tag used to populate the collection.
- TITLE -- Returns whatever was placed in the TITLE attribute in the CFINDEX operation used to populate the collection, including the titles of PDF and Office documents. If no title was provided in the TITLE attribute, CFSEARCH returns CF_TITLE.
- SCORE -- Returns the relevancy score of the document based on the search criteria.
- CUSTOM1 and CUSTOM2 -- Returns whatever was placed in the custom fields in the CFINDEX operation used to populate the collection.
- SUMMARY -- Returns the contents of the automatic summary generated by CFINDEX. The default summarization selects the best three matching sentences, up to a maximum of 500 characters.
- RECORDCOUNT -- Returns the number of records returned in the record set.
- CURRENTROW -- Returns the current row being processed by CFOUTPUT.
- COLUMNLIST -- Returns the list of the column names within the record set.
- RECORDSSEARCHED-- Returns the number of records searched.

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

    #DocSearch.URL#
    #DocSearch.KEY#
    #DocSearch.TITLE#
    #DocSearch.SCORE#

### Example

    <!--- This example shows how to utilize CFSEARCH
    to search an existing, populated collection  --->
    <HTML>
    <HEAD>
    <TITLE>
    CFSEARCH Example
    </TITLE>
    </HEAD>

    <BODY bgcolor=silver>
    <H3>CFSEARCH Example</H3>

    <!--- To index the collection, select the check box
    on the form --->
    <CFIF IsDefined("form.IndexCollection")>
    <!--- Change KEY and URLPATH to reflect accurate key and URL
    <CFINDEX ACTION="UPDATE" COLLECTION="Snippets"
       KEY="c:\inetpub\wwwroot\cfdocs\snippets" TYPE="PATH"
         TITLE="This is my test" URLPATH="http://127.0.0.1/cfdocs/snippets/"
           EXTENSIONS=".cfm" RECURSE="Yes">
    <H3>Collection re-indexed</H3>
    </CFIF>
    <CFIF IsDefined("form.source") AND
    IsDefined("form.type") AND IsDefined("form.searchstring")>

    <!--- actually conduct the search --->
        <CFSEARCH NAME="SearchSnippets"
        COLLECTION="#form.source#"
        TYPE="#form.type#"
        CRITERIA="#form.searchstring#">

    <!--- print out the search results --->
        <CFOUTPUT>
        <H2>#form.type# Search Results</H2>

        <P>#SearchSnippets.RecordCount# "hit
          <CFIF SearchSnippets.recordcount is not 1>s</CFIF>" found
            out of #SearchSnippets.RecordsSearched# total record
              <CFIF SearchSnippets.recordcount is not 1>s</CFIF>
                searched.

        <P><I><B>#form.maxrows# records returned ...</B></I>

        <CFTABLE QUERY="SearchSnippets" MAXROWS="#maxrows#"
          STARTROW="1" COLHEADERS HTMLTABLE>
            <CFCOL HEADER="SCORE" TEXT="#score#">
            <CFCOL HEADER="TITLE"
              TEXT="<a href='#url#' target='blank'>#title#</A>">
            <CFCOL HEADER="SUMMARY" TEXT="#summary#">
        </CFTABLE>
        </CFOUTPUT>

    </CFIF>
    ...