Whatever message this page gives is out now! Go check it out!
cfindex supports script style syntax:
new index(collection="<collection_name>");
<cfindex
action = "update|delete|purge|refresh|fullimport|deltaimport|status|abort|optimize"
autoCommit = "yes|no"
collection = "collection name"
collectionNames= "comma-separated values of collection names"
body = "body"
category = "category name"
categoryTree = "category tree"
custom1 = "custom value"
custom2 = "custom value"
custom3 = "custom value"
custom4 = "custom value"
extensions = "file extensions"
key = "ID"
language = "{{language}}"
prefix = "location of documents"
query = "query name"
recurse = "yes|no"
status = "status"
throwOnError="true|false"
title = "title"
type = "type"
URLpath = "URL">| Attribute | Req/Opt | Default | Description |
action | Required | Null |
|
autoCommit | Optional | True | If yes, automatically commit the changes to the search server. If no, indexed documents are not committed unless you specifically commit using cfindex action="commit". By default, the value is set to true. |
collection | Required | Null | Name of a collection that is registered by ColdFusion; for example, " personnel ". |
| collectionNames | Optional | Null | Comma-separated values of collection names. Note: This attribute is required when action="merge". |
body | Required if type=custom | Null |
|
category | Optional | (empty string) | A string value that specifies one or more search categories for which to index the data. You can define multiple categories, separated by commas, for a single index. If you use a query for your indexed data, this value can be the name of a column. |
categoryTree | Optional | (empty string) | A string value that specifies a hierarchical category or category tree for searching. It is a series of categories separated by forward slashes ("/"). You can specify only one category tree. |
custom1 | Optional | Null | Use to index discrete values in collection records, which lets you search for specific records. By contrast, values specified in the body attribute are concatenated and searched as a body of text using the specified criteria. If type = custom, a query column name. If type is file or path, a string. Additionally, ColdFusion 10 added support for dynamic custom fields. |
custom2 | Optional | Null | Usage is the same as for custom1. |
custom3 | Optional | Null | Usage is the same as for custom1. |
custom4 | Optional | Null | Usage is the same as for custom1. |
extensions | Optional | htm , html , cfm , cfml , dbm , dbml | Delimited list of file extensions that ColdFusion uses to index files, if type = "Path". "." returns files with no extension. "." returns all files. For example, the following code returns files with a listed extension or no extension: extensions = ".htm, .html, .cfm, .cfml, *." |
fieldBoost | Optional | htm , html , cfm , cfml , dbm , dbml | Boost specific fields while indexing. fieldBoost enhances the score of the fields and thereby the ranking in the search results. Multiple fields can be boosted by specifying the values as a comma-separated list. This attribute is removed in ColdFusion (2025 release). |
key | Required | (empty string) | The value specified for key depends on the type attribute:
|
language | Optional | Null | For options, see cfcollection . |
prefix | Optional | Null | Specifies the location of files to index when the computer that contains the K2 Search Service is not the computer on which you installed ColdFusion, and when you index files with the type attribute set to path . |
query | Optional. | Null | The name of the query against which the collection is generated. |
recurse | Optional | no |
|
status | Optional | Null | The name of the structure into which ColdFusion returns status information. |
| throwOnError | Oprtional | false | If true, then cfindex tag throws an error while indexing documents. |
title | Optional | (empty string) | Provides a title for the document if one cannot be extracted from the document. |
type | Optional | custom, if query attribute is specified. Otherwise, file. |
When type=" dih ", these actions are used:
|
URLpath | Optional | (empty string) | If type is file or path, specifies the URL path. During indexing, this pathname is prefixed to filenames and returned from a search as the url . |
| Type | Attribute values |
File | The key attribute is the name of a column in the query that contains a full filename (including path). |
Path | The key attribute is the name of a column in the query that contains a directory pathname. |
The extensions and recurse attributes, if specified, elaborate on which files are included. If the action is delete, cfindex deletes keys for the collection. | |
Custom | The key attribute specifies a column name that contains anything you want; for example, the primary key value in the database. It must be unique because this is the primary key in the collection. If the action is delete, the key attribute is the name of a column in the query that contains the keys to delete. |
The body attribute is required and is a comma-delimited list of the names of the columns that contain the text data to be indexed. |
| Type | Attribute values |
File | The key attribute is required and is a full pathname to a file. |
Path | The key attribute is required and it is a directory pathname. |
The extensions and recurse attributes, if specified, designate which types of files are included. If the action is delete, both the keys and the document files are deleted. | |
Custom | The key attribute is an identifier that specifies the key. If the action is delete, the key attribute is the document key to delete. |
The body attribute is required and is the text to be indexed. |
| Key | Type | Description |
BADKEYS | Struct | A structure of keys with diagnostic messages about the indexing of these keys. If there are no bad keys, this key does not exist. |
DELETED | Number | The number of keys deleted. |
MESSAGES | Array | An array of diagnostic messages, including nonfatal errors and warnings. If there are no messages, this key does not exist. |
INSERTED | Number | The number of keys inserted into the collection. |
UPDATED | Number | The number of keys updated in the collection. |
<!--- EXAMPLE #1 Index a file, type = "file". ---------------------------->
<!--- Example dumps content of status variable (info). ------------------->
<cfindex collection="CodeColl"
action="refresh"
type="file"
key="C:\ColdFusion\wwwroot\vw_files\cfindex.htm"
urlpath="http://localhost:8500/vw_files/"
language="English"
title="Cfindex Reference page"
status="info">
<!--- Search for Attributes. --->
<cfsearch
name = "mySearch"
collection = "CodeColl"
criteria = "Attributes"
contextpassages = "1"
maxrows = "100">
<cfoutput>
key=#mySearch.key#<br />
title=#mySearch.title#<br />
context=#mySearch.context#<br />
url=#mySearch.url#<br />
</cfoutput>
<cfdump var="#info#">
<!--- EXAMPLE #2 Index a path (type = "path"). ------------------------------>
<cfindex collection="CodeColl"
action="refresh"
type="path"
key="C:\inetpub\wwwroot\vw_files\newspaper\sports"
urlpath="http://localhost/vw_files/newspaper/sports"
extensions = ".htm, .html"
recurse="no"
language="English"
categoryTree="vw_files/newspaper/sports"
category="Giants">
<!--- Search for any references to criteria. --->
<cfsearch
name = "mySearch"
collection = "CodeColl"
categoryTree="vw_files/newspaper/sports"
category="Giants"
criteria = "Williams"
contextpassages = "1"
maxrows = "100">
<cfoutput>
key=#mySearch.key#<br />
title=#mySearch.title#<br />
context=#mySearch.context#<br />
url=#mySearch.url#<br />
</cfoutput>
<!---EXAMPLE #3: Index a QUERY (type = "custom") using custom1. ------------>
<!--- Retrieve data from the table. --->
<cfquery name="getCourses" datasource="cfdocexamples">
SELECT * FROM COURSES
</cfquery>
<!--- Update the collection with the above query results. --->
<!--- key is Course_ID in the Courses table. ---->
<!--- body specifies the columns to be indexed for searching. --->
<!--- custom1 specifies the value of the Course_Number column. --->
<cfindex
query="getCourses"
collection="CodeColl"
action="Update"
type="Custom"
key="Course_ID"
title="Courses"
body="Course_ID,Descript"
custom1="Course_Number"
>
<h2>Indexing Complete</h2>
<!--- cno supplies value for searching custom1; could be form input instead. --->
<cfset cno = "540">
<cfsearch
name = "mySearch"
collection = "CodeColl"
criteria = "CF_CUSTOM1 <MATCHES> #cno#"
contextpassages = "1"
maxrows = "100">
<!--- Returns indexed values (Course_ID and Descript) for
Course_Number 540. --->
<cfoutput>
key=#mySearch.key#<br />
title=#mySearch.title#<br />
context=#mySearch.context#<br />
url=#mySearch.url#<br />
</cfoutput>
<!--- EXAMPLE #4 Index a FILE within a QUERY (type= "file"). --------------->
<!--- Retrieve row with a column that contains a filename (Contract_File). --->
<cfquery name="getEmps" datasource="cfdocexamples">
SELECT * FROM EMPLOYEE WHERE EMP_ID = 1
</cfquery>
<!--- Update the collection with the above query results. --->
<!--- key specifies the column that contains a complete filename. --->
<!--- file is indexed in same way as if no query involved. --->
<cfindex
query="getEmps"
collection="CodeColl"
action="Update"
type="file"
key="Contract_File"
title="Contract_File"
body="Emp_ID,FirstName,LastName,Contract_File">
<h2>Indexing Complete</h2>
<cfsearch
name = "mySearch"
collection = "CodeColl"
criteria = "vacation"
contextpassages = "1"
maxrows = "100">
<cfoutput>
key=#mySearch.key#<br />
title=#mySearch.title#<br />
context=#mySearch.context#<br />
url=#mySearch.url#<br />
</cfoutput>
<!--- EXAMPLE # 5 Index a PATH within a QUERY. ---------------------------->
<!--- Retrieve a row with a column that contains a path (Project_Docs). --->
<cfquery name="getEmps" datasource="cfdocexamples">
SELECT * FROM EMPLOYEE WHERE Emp_ID = 15
</cfquery>
<!--- Update the collection with the above query results. --->
<!--- key specifies a column that contains a directory path. --->
<!--- path is indexed in same way as if no query involved. --->
<cfindex
query="getEmps"
collection="CodeColl"
action="update"
type="path"
key="Project_Docs"
title="Project_Docs"
body="Emp_ID,FirstName,LastName,Project_Docs">
<h2>Indexing Complete</h2>
<cfsearch
name = "getEmps"
collection = "CodeColl"
criteria = "cfsetting"
contextpassages = "1"
maxrows = "100">
<cfoutput>
key=#getEmps.key#<br />
title=#getEmps.title#<br />
context=#getEmps.context#<br />
url=#getEmps.url#<br />
</cfoutput>
<!--- EXAMPLE #6 Deletes keys in the CodeColl collection for html files --->
<!--- in the specified directory (but not in subdirectories). ------------->
<cfindex collection="CodeColl"
action="delete"
type="path"
key="C:\ColdFusion\wwwroot\vw_files\newspaper"
urlpath="http://localhost:8500/vw_files/newspaper"
extensions = ".htm, .html"
recurse="no">
<!--- EXAMPLE #7 Purges all keys in the CodeColl collection --->
<!--- with recursion. ------------------------------------------------------->
<cfindex collection="CodeColl"
action="purge"
type="path"
key="C:\ColdFusion\wwwroot\vw_files\newspaper">