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");

cfcollection Attribute Reference

action
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

A collection name. The name can include spaces

path

Absolute path to a Verity/Lucene/SOLR collection.

language
Default: english

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

name

Name for the query results returned by the list action.

categories
Default: NO

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

engine
Default: verity

Search engine Values:
  • verity
  • solr

Examples sample code using the cfcollection tag


Example of using the cfcollection function to create a collection

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


Example of using the <cfcollection> tag to create a collection

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


Fork me on GitHub