cfsearch

Description

Executes 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.

Category

Extensibility tags

Syntax


<cfsearch name = "search_name"

  collection = "collection_name"

  type = "criteria"

  criteria = "search_expression"

  maxRows = "number"

  startRow = "row_number"

  external = "Yes" or "No"

  language = "language"> 

See also

cfcollection, cfreport, cfexecute, cfgraph, cfservlet, cfindex, cfservletparam, cfobject, cfwddx

Attributes

Attribute
Description
name
Required. A name for the search query.
collection
Required. 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 = "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, 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.

cfsearch result columns
Variable
Description
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
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>

...



Banner.Novgorod.Ru