User Guide Cancel

cfsearch

 

Description

Searches one or more Solr collections.A collection must be created and indexed before this tag can return search results.A collection can be created in these ways:

  • With the cfcollection tag
  • In the ColdFusion Administrator
    A collection can be indexed in the following ways:
  • In ColdFusion, with the cfindex tag
  • In the ColdFusion Administrator, which calls the cfindex tag
    For more information, see Building a Search Interface in the Developing ColdFusion Applications.

Category

Syntax

cfsearch supports script style syntax:
cfsearch(name="<search_name>", collection="<collection_name>");
<cfsearch
collection = "collection name"
name = "search name"
category = "category[,category2,...]"
categoryTree = "tree location"
contextBytes = "number of bytes"
contextHighlightBegin = "HTML string"
contextHighlightEnd = "HTML string"
contextPassages = "number of passages"
criteria = "search expression"
maxRows = "number"
orderBy = "rank_order"
previousCriteria = "criteria"
startRow = "row number"
status = ""
suggestions = "suggestion option"
type = "criteria">
cfsearch supports script style syntax: cfsearch(name="<search_name>", collection="<collection_name>"); <cfsearch collection = "collection name" name = "search name" category = "category[,category2,...]" categoryTree = "tree location" contextBytes = "number of bytes" contextHighlightBegin = "HTML string" contextHighlightEnd = "HTML string" contextPassages = "number of passages" criteria = "search expression" maxRows = "number" orderBy = "rank_order" previousCriteria = "criteria" startRow = "row number" status = "" suggestions = "suggestion option" type = "criteria">
cfsearch supports script style syntax: 

cfsearch(name="<search_name>", collection="<collection_name>"); 

<cfsearch 
collection = "collection name" 
name = "search name" 
category = "category[,category2,...]" 
categoryTree = "tree location" 
contextBytes = "number of bytes" 
contextHighlightBegin = "HTML string" 
contextHighlightEnd = "HTML string" 
contextPassages = "number of passages" 
criteria = "search expression" 
maxRows = "number" 
orderBy = "rank_order" 
previousCriteria = "criteria" 
startRow = "row number" 
status = "" 
suggestions = "suggestion option" 
type = "criteria">
Note:

You can specify this tag's attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag's attribute names as structure keys.

Note:

The attributes contextHighlightBegin, contextHighlightEnd, and contextBytes should be used only if Term Highlighting is enabled for the collection in the ColdFusion Administrator.

Enable Term Highlighting using Data & Services > ColdFusion Collections > Manage Collection.

See also

History

ColdFusion (2025 release): Removed the attribute external.

ColdFusion 11: Removed the attributes language.

ColdFusion 10: New attribute orderBy

ColdFusion 9: Added support for Solr search engine.

ColdFusion MX 7:

  • Added category, categoryTree, status, suggestions, contextPassages, contextBytes, 
    contextHighlightBegin, contextHighlightEnd, and previousCriteria attributes.
  • Added author, category, categoryTree, context, rank, size, recordsSearched, and type result columns.
  • Added information on the status structure and its associated keys.
  • Removed references to a separate K2 server and k2server.ini file.
  • Removed references to unregistered collections.
  • Removed references to external collections. ColdFusion MX now manages all collections through the Verity Search service.
  • Changed cflock recommendation. It is no longer a best practice to surround the cfsearch tag with a cflock tag.
    ColdFusion MX:
  • Deprecated the external attribute. 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.
  • Changed query result behavior: the cfindex tag can index the query results from a cfsearch operation.
  • Changed Verity operations behavior: ColdFusion supports Verity operations on Acrobat PDF files.
  • Changed multiple collection behavior: this tag can search multiple collections. In a multiple collection search, you cannot combine collections that are registered with K2Server and registered in another way.
  • Changed acceptable collection naming: this tag accepts collection names that include spaces.
  • Changed the following support: this tag supports Verity 2.6.1 and the LinguistX and ICU locales.
  • Changed thrown exceptions: 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 collection names. You can specify more than one collection unless you are performing a category search (that is, specifying category or categoryTree).

category

Optional

 

A list of categories, separated by commas, to which the search is limited. If specified, and the collection does not have categories enabled, ColdFusion throws an exception.

categoryTree

Optional

 

The location in a hierarchical category tree at which to start the search. ColdFusion searches at and below this level. If specified, and the collection does not have categories enabled, ColdFusion throws an exception. Can be used in addition to the category attribute.

criteria

Optional

 

Search criteria. Follows the syntax rules of the type attribute. The search is case-insensitive. Follow Solr syntax and delimiter character rules; see Solr search support in the Developing ColdFusion Applications.

contextBytes

OptionalSolr

300

The maximum number of bytes returned in the context summary.

contextHighlightBegin

OptionalSolr

<b>

The HTML to prepend to search terms in the context summary. Use this attribute in conjunction with contextHighlightEnd to highlight search terms in the context summary.

contextHighlightEnd

OptionalSolr

</b>

The HTML to append to search terms in the context summary. Use this attribute in conjunction with contextHighlightBegin to highlight search terms in the context summary.

contextPassages

OptionalSolr

0

The number of passages/sentences Solr returns in the context summary (that is, the context column of the results). The default is 0, which disables context summary.

language

Optional

english

Deprecated. This attribute is now ignored and the language of the collection is used to perform the search.

maxRows

Optional

all

Maximum number of rows to return in query results.

orderBy

Optional

 

Sorts the custom field column rank order. By default, it sorts in ascending order.

previousCriteria

Optional

 

The name of a result set from an existing set of search results. The search engine searches the result set for criteria without regard to the previous search score or rank. Use this attribute to implement searching within result sets.

startRow

Optional

1

Row number of the first row to get.

status

Optional

 

Specifies the name of the structure variable into which ColdFusion places search information, including alternative criteria suggestions (spelling corrections). For a list of keys in this structure, see the section Status structure keys.

suggestions

Optional

never

Specifies whether the search engine returns spelling suggestions for possibly misspelled words. Use one of the following options:

  • Always: Always return spelling suggestions.
  • Never: Never return spelling suggestions.
  • positive integer: Return spelling suggestions if the number of documents retrieved by the search is less than or equal to the number specified.
    There is a small performance penalty for retrieving suggestion data.

type

Optional

standard

Specifies the parser that the engine uses to process the criteria.
  • Standard
  • DisMax

Usage

The cfsearch tag returns a query object 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="standard"
startrow=1
maxrows = "100">
<cfdump var = "#mySearch#>
<cfsearch name = "mySearch" collection = "myCollection" criteria = '<WILDCARD>`film{ing,ed}`' type="standard" startrow=1 maxrows = "100"> <cfdump var = "#mySearch#>
<cfsearch 
name = "mySearch" 
collection = "myCollection" 
criteria = '<WILDCARD>`film{ing,ed}`' 
type="standard" 
startrow=1 
maxrows = "100"> 
<cfdump var = "#mySearch#>

In this example, the single-quotation mark (') and backtick (`) characters are used as delimiters.

To optimize search performance, always specify the maxrows attribute, setting it to a value that matches your application's needs. A value less than 300 helps to ensure optimal performance.Adobe does not recommend using the cflock tag with this tag; Solr provides the locking function. Using the  cflock tag slows search performance.

The cfsearch tag result columns

Variable

Description

context

A context summary containing the search terms, highlighted in bold (by default). This is enabled if you set the contextpassages attribute to a number greater than zero.

url

Value of URLpath attribute in the cfindex tag used to populate a collection.

key

Value of the key attribute in the cfindex tag used to populate a collection.

title

Value of title attribute in cfindex tag used to populate the collection, including PDF and Office document titles. If a title is not extracted from the document, the tag uses the cfindex title attribute value for each row.

score

Relevancy score of document based on search criteria

custom1, custom2, custom3, custom4

Value of custom fields in cfindex tag used to populate a collection.

size

The number of bytes in the index document.

rank

The rank of this document in the search results.

author

Extracted from the HTML, Office, and PDF documents when available.

type

The MIME type of the document.

category

A list of the categories that were specified for this document when it was indexed.

categoryTree

A hierarchical category tree, or serial list of categories, that was specified for this document when it was indexed. Only a single tree is returned.

summary

Contents of automatic summary generated by cfindex.

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. This is the same value for each row in the record set. Corresponds to the searched key in the status structure.

Status structure keys

Variable

Description

found

The number of documents that contain the search criteria.

searched

The number of documents searched. Corresponds to the recordsSearched column in the search results.

time

The number of milliseconds the search took.

suggestedQuery

An alternative query that might produce better results. This often contains corrected spellings of search terms. Present only when the suggestions tag attribute criteria is met.

keyword

A struct of structs that consists of keys corresponding to the terms specified in the search criteria. Each struct key maps to a struct containing key-value pairs where each key is a suggested keyword and the corresponding value is the number of times the keyword appears in the index data.

Keywords appear only if the search criteria is not met. An empty struct is returned otherwise.

Example

<!--- #3 (search by CF key) ----------------------------->
<cfsearch
name = "book"
collection = "custom_book"
criteria = "cf_key=bookid2"
maxrows = "100">
<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#>
<!--- #3 (search by CF key) -----------------------------> <cfsearch name = "book" collection = "custom_book" criteria = "cf_key=bookid2" maxrows = "100"> <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#>
<!--- #3 (search by CF key) -----------------------------> 
<cfsearch 
name = "book" 
collection = "custom_book" 
criteria = "cf_key=bookid2" 
maxrows = "100"> 
<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#>

Get help faster and easier

New user?