DevLearningTools

MODULE 14 · LESSON 08

cfcollection

Creating and managing a full-text search collection with cfcollection: the first of three connected tags (cfcollection, cfindex, cfsearch) for fast search across documents or database records, and the real Verity-to-Solr engine history worth knowing.

New lessons are added one at a time as the course gets built out — a graded quiz for each lesson is still on the way.

Searching thousands of records or documents by filtering with SQL LIKE '%term%' gets slow and imprecise fast, no relevance ranking, no partial-word matching, no highlighting. ColdFusion's built-in full-text search solves that with three tags used together: cfcollection creates the search index's container, cfindex fills it with data, and cfsearch queries it. This lesson covers the first step.

Learning Objectives

After completing this lesson, you'll be able to:

  • Explain what a search collection actually is, and why full-text search needs one.
  • Create, list, and delete a collection with cfcollection.
  • Know the real history behind the engine attribute: Verity, then Solr.
  • Check whether a collection already exists before creating it.

The Three-Tag Workflow

cfcollection

create the container

cfindex

fill it with data

cfsearch

query it, ranked by relevance

A Real Detail: Verity, Then Solr

Worth knowing before the attribute tables below make less sense: ColdFusion's search engine changed over the years. Older versions used Verity, and a fair amount of documentation (including parts of cfdocs.org's current cfcollection and cfindex pages) still describes that era, engine defaulting to "verity". Modern Adobe ColdFusion has fully moved to Apache Solr instead, engine="solr" is the only real option going forward, per Adobe's own current documentation. Lucee accepts the engine attribute for compatibility but ignores it, running its own Lucene-based search engine internally regardless of what's passed.

NOTE

If a collection created in an old CF instance won't open on a newer one, or a tutorial you find online doesn't match what you're seeing, the Verity-to-Solr transition is very often why.

Creating a Collection

Tag Syntax
<cfcollection action="create" collection="productDocs" engine="solr">
CFScript
cfcollection(action = "create", collection = "productDocs", engine = "solr");

Key Attributes

AttributeMeaning
actioncreate, delete, list, optimize, reload, categorylist, or map (default: list)
collectionThe collection's name, case-sensitive
engine"solr" on modern Adobe ColdFusion, accepted-but-ignored on Lucee
languageCollection's language (default: English)
categoriesyes/no, whether the collection supports category tagging

A Real Example: Check Before You Create

Creating a collection that already exists throws an error, so a real application typically lists existing collections first and checks, exactly the pattern Adobe's own documentation shows.

CFScript
cfcollection(action = "list", name = "existingCollections");

existingQuery = queryExecute(
    "SELECT * FROM existingCollections WHERE name = :name",
    { name: "productDocs" },
    { dbtype: "query" }
);

if (existingQuery.recordCount EQ 0) {
    cfcollection(action = "create", collection = "productDocs", engine = "solr");
}
NOTE

That queryExecute with dbtype="query" is a Query of Queries, running SQL directly against the in-memory query object cfcollection's list action returned, no database round trip needed.

Common Beginner Mistakes

Calling action="create" without checking if the collection already exists

That throws an exception. List existing collections first (action="list") and check, as shown above, rather than assuming the collection is new.

Expecting engine="verity" to work on a modern Adobe ColdFusion instance

Verity was replaced by Solr; current Adobe documentation only describes the Solr engine going forward. Older tutorials referencing Verity are describing a legacy version.

Trying to use a collection before indexing anything into it

cfcollection only creates the empty container. Nothing is searchable until cfindex (the next lesson) actually populates it with data.

Best Practices

  • Always check whether a collection exists (action="list" + a Query of Queries) before calling action="create".
  • Use engine="solr" explicitly on Adobe ColdFusion, don't rely on defaults that may reflect older documentation.
  • Pick a clear, descriptive collection name, it's referenced by every later cfindex and cfsearch call.

Interview Questions

What's the relationship between cfcollection, cfindex, and cfsearch?

cfcollection creates and manages the search index's container. cfindex populates that container with data, files or CFML query result sets. cfsearch queries the populated collection and returns ranked results. All three work together; none is useful alone.

What search engine does modern ColdFusion use for cfcollection, and what did it use before?

Modern Adobe ColdFusion uses Apache Solr. Older versions used Verity, which is why engine="verity" still shows up in some documentation and older tutorials. Lucee runs its own Lucene-based engine and ignores the engine attribute entirely.

Summary

In this lesson, you created a search collection with cfcollection, covered the real Verity-to-Solr engine history, and checked for an existing collection with a Query of Queries before creating a new one.

What's Next?

The next lesson covers cfindex: actually populating the collection you just created, with files, a directory, or a CFML query's results.