# Creating a Collection

The Verity engine performs searches against collections. A collection is a special database created by Verity that contains pointers to the indexed data that you specify for that collection. ColdFusion's Verity implementation supports collections of three basic data types:

- Text files such as HTML pages and CFML templates.
- Binary documents (see the Supported File Types list).
- Result sets returned from CFQUERY, CFLDAP, and CFPOP queries.

You can build a collection from individual documents or an entire directory tree. Collections can be stored anywhere, so you have a lot of flexibility in accessing indexed data. This adds enormous value to any content-rich Web site.

ColdFusion provides twodifferent ways to create a Verity collection. You can:

- Make selections on the ColdFusion Administrator Verity page
- Code the CFCOLLECTION tag

## Using the ColdFusion Administrator to create a collection

| To create a new collection:

1. Open the ColdFusion Administrator Verity page.

   If you checked the option to install the ColdFusion Documentation, the documentation collection is listed by default. The Verity engine is used to search our online documents.

2. In the Add a Collection section, enter a name for the collection.
3. Enter a path for the location of the new collection.

   By default, new collections are added to `\Cfusion\Verity\Collections\`.

4. If you have an International Language Search Pack installed, you can select a language for the collection from the drop-down list.
5. Click Create a new collection, then click Apply.

   When the collection is created, the name and full path of the new collection appear in the Verity Collections list at the top of the page.

You can easily enable access to a collection on the network by creating a local reference (an alias) for that collection. It only needs to be a valid Verity collection; it doesn't matter whether it was created within ColdFusion or another tool.

| To add an existing collection:

1. In the Add a Collection section, enter the collection alias.
2. Enter the full path to the collection.
3. Select Language if needed.
4. Click Map an existing collection.
5. Click Apply.

If the collection is subsequently moved, the alias path must be updated. The Delete command, when used on a mapped collection, only deletes the alias.

## Creating a collection with the CFCOLLECTION tag

Creating and maintaining collections from a CFML application eliminates the need to access the ColdFusion Administrator. This can be an advantage when you need to schedule these tasks or to allow users to perform them without exposing the Administrator to users.

| To create a simple collection form page:

1. Open a new file in Studio.
2. Modify the file so that it appears as follows:

       <HTML>
       <HEAD>
           <TITLE>Collection Creation Input Form</TITLE>
       </HEAD>

       <BODY>
       <H2>Specify a collection</H2>
       <FORM ACTION="collectioncreateaction.cfm" METHOD="POST">
           <P>Collection name: <INPUT TYPE="text" NAME="CollectionName"
       SIZE="25"></P>
           <P>What do you want to do with the collection?</P>
           <INPUT TYPE="radio"
               NAME="CollectionAction"
               VALUE="Create" checked>Create<BR>
           <INPUT TYPE="radio"
               NAME="CollectionAction"
               VALUE="Repair">Repair<BR>
           <INPUT TYPE="radio"
               NAME="CollectionAction"
               VALUE="Optimize">Optimize<BR>
           </P>
           <INPUT TYPE="submit"
               NAME="submit"
               VALUE="Submit">
       </FORM>

       </BODY>
       </HTML>

3. Save the file as `collectioncreateform.cfm`.

Note that this file simply shows how the form variables are used and does not perform error checking.

| To create a collection action page:

1. Open a new file in Studio.
2. Modify the file so that it appears as follows:

       <HTML>
       <HEAD>
           <TITLE>CFCOLLECTION</TITLE>
       </HEAD>

       <BODY>
       <H2>Collection creation</H2>

       <CFOUTPUT>

           <CFSWITCH EXPRESSION=#FORM.CollectionAction#>
               <CFCASE VALUE="Create">
                   <CFCOLLECTION ACTION="Create"
                   COLLECTION="#FORM.CollectionName#"
                   PATH="C:\CFUSION\Verity\Collections\">
                   <P>The collection #FORM.CollectionName# is created.
               </CFCASE>

               <CFCASE VALUE="Repair">
                   <CFCOLLECTION ACTION="REPAIR"
                   COLLECTION="#FORM.CollectionName#">
                   <P>The collection #FORM.CollectionName# is repaired.
               </CFCASE>

               <CFCASE VALUE="Optimize">
                   <CFCOLLECTION ACTION="OPTIMIZE"
                   COLLECTION="#FORM.CollectionName#">
                   <P>The collection #FORM.CollectionName# is optimized.
               </CFCASE>

               <CFCASE VALUE="Delete">
                   <CFCOLLECTION ACTION="DELETE"
                   COLLECTION="#FORM.CollectionName#">
                   <P>Collection deleted.
               </CFCASE>
           </CFSWITCH>
       </CFOUTPUT>
       </BODY>
       </HTML>

3. Save the file as `collectioncreateaction.cfm`.
4. View the file `collectioncreateform.cfm` in your browser, enter values and submit the form.