You can retrieve the category information for a collection by using the cfcollection tag's categoryList action. The categoryList action returns a structure that contains two keys:
Variable |
Description |
---|---|
categories |
The name of the category and its hit count, where hit count is the number of documents in the specified category. |
categorytrees |
The document tree (a/b/c) and hit count, where hit count is the number of documents at or below the branch of the document tree. |
You can use the information returned by categoryList to display to users the number of documents available for searching, as well the document tree available for searching. You can also create a search interface that lets the user select what category to search within based on the results returned by categoryList.
<cfcollection action="categoryList" collection="collectionName" name="info"> <cfoutput> <cfset catStruct=info.categories> <cfset catList=StructKeyList(catStruct)> <cfloop list="catList" index="cat"> Category: #cat# <br> Documents: #catStruct[cat]#<br> </cfloop> </cfoutput>
To retrieve information about the categories contained in a collection, you use the cfcollection tag, and create an application page that retrieves category information from the collection and displays the number of documents contained by each category. This example lets the user enter and submit the name of the collection via a form, and then uses the categoryList action to retrieve information about the number of documents contained by the collection, and the hierarchical tree structure into which the category is organized.
<html> <head> <title>Category information</title> </head> <body> <cfoutput> <form action="#CGI.SCRIPT_NAME#" method="POST"> Enter Collection Name: <input Type="text" Name="collection" value="#collection#"><br> <input Type="submit" Value="GetInfo"> </form> </cfoutput> <cfif isdefined("Form.collection")> <cfoutput> Getting collection info... <br> <cfflush> <cfcollection action="categorylist" collection="#collection#" name="out"> <br> <cfset categories=out.categories> <cfset tree=out.categorytrees> <cfset klist=StructKeyList(categories)> <table border=1> <th>Category</th> <th>Documents</th> <cfloop index="x" list="#klist#"> <tr> <td>#x#</td> <td align="center">#categories[x]#</td> </tr> </cfloop> </table> <cfset klist=StructKeyList(tree)> <table border=1> <th>Category</th> <th>Documents</th> <cfloop index="x" list="#klist#"> <tr> <td>#x#</td> <td align="center">#tree[x]#</td> </tr> </cfloop> </table> </cfoutput> </cfif> </body>
For more information on using the cfcollection tag to create Verity collections with support for categories, see cfcollection in CFML Reference.