cfcollection

Creates, registers, and administers Verity search engine
collections.

A collection that is created with the cfcollection tag is
internal. A collection created any other way is external.

A collection that is registered with CFML using the
cfcollection tag or registered with the K2 Server by editing
the k2server.ini file is registered. Other collections are
unregistered.

  <cfcollection action="categorylist">

 cfcollection(action="categorylist");

Attribute Reference

action string
Required
Default: list

categorylist: retrieves categories from the collection and
indicates how many documents are in each one. Returns
a structure of structures in which the category
representing each substructure is associated with a
number of documents. For a category in a category tree,
the number of documents is the number at or below that
level in the tree.
create: registers the collection with CFML.
- If the collection is present: creates a map to it
- If the collection is not present: creates it
delete: unregisters a collection.
- If the collection was registered with action = create:
deletes its directories
- If the collection was registered and mapped: does not
delete collection directories
optimize: optimizes the structure and contents of the
collection for searching; recovers space.
list: returns a query result set, named from the name
attribute value, of the attributes of the collections
that are registered by CFML and K2 Server.
map: creates a map to the collection. It is not necessary
to specify this value. Deprecated in CF7.
repair: fixes data corruption in a collection. Deprecated in CF7.
Values:
  • categorylist
  • create
  • delete
  • optimize
  • list
  • map
  • repair

collection string

A collection name. The name can include spaces

path string

Absolute path to a Verity/Lucene/SOLR collection.

language string
Default: english

Options are listed in Usage section. Requires the
appropriate (European or Asian) Verity Locales language
pack.

name string

Name for the query results returned by the list action.

categories boolean
Default: false

Used only for creating a collection:
- true: This collection includes support for categories.
- false: This collection does not support categories. Default.
Values:
  • true
  • false

engine string
Default: verity

Search engine
Values:
  • verity
  • solr

Examples
Sample code using the cfcollection tag

In this example we demonstrate using the cfcollection function to build a function which first checks if a collection already exists (and has records), and if not, creates the collection.

public boolean function createCollection( required string collectionName ) {
	// var scope a variable to check if the collection already exists
	var collectionExists = '';

	// use cfcollection to get a list of documents from the passed in collection
	cfcollection( action = 'list', collection = arguments.collectionName, name = 'collectionExists' );

	// see if the collection has any records
	if( !collectionExists.recordCount ) {
		// it does not, but wrap create in a try in case it exists but is merely empty
		try {
			// use cfcollection to create a new collection
			cfcollection( action = 'create', collection = arguments.collectionName );
		// catch if this collection already exists
		} catch (any e) {
			// it does, return false
			return false;
		}
	// otherwise
	} else {
		// collection already has records (and thus exists), return false
		return false;
	}

	// the collection was successfully created, return true
	return true;
}

Expected Result: True, if the collection was created; False, if the collection already exists

In this example we demonstrate using the <cfcollection> tag to build a function which first checks if a collection already exists (and has records), and if not, creates the collection.

<cffunction access="public" returntype="boolean" name="createCollection">
	<cfargument name="collectionName" type="string" required="true" />

	<!--- var scope a variable to check if the collection already exists --->
	<cfset var collectionExists = ""; />

	<!--- use cfcollection to get a list of documents from the passed in collection --->
	<cfcollection action="list" collection="#arguments.collectionName#" name="collectionExists" />

	<!--- see if the collection has any records --->
	<cfif NOT collectionExists.recordCount>
		<!--- it doesn't, but wrap create in a try in case it exists but is merely empty --->
		<cftry>
			<!--- use cfcollection to create a new collection --->
			<cfcollection action="create" collection="#arguments.collectionName#" />
		<!--- catch if this collection already exists --->
		<cfcatch type="any">
			<!--- it does, return false --->
			<cfreturn false />
		</cfcatch>
		</cftry>
	<!--- otherwise --->
	<cfelse>
		<!--- collection already has records (and thus exists), return false --->
		<cfreturn false />
	</cfif>

	<!--- the collection was successfully created, return true --->
	<cfreturn true />
</cffunction>

Expected Result: True, if the collection was created; False, if the collection already exists

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub