The following code examples demonstrate a very basic approach to populating and searching a collection of ASCII text data and a collection of data from an ODBC data source. To run the example, save the code examples into the indicated file names all in the same directory. Then open the start.cfm to run the example.
Contents
This first sample, start.cfm, provides a simple starting point for populating a collection. You can use the code as is, with a few minor changes. Note that for this sample to work, you'll need to first create two collections using the Verity Collection Administrator, one called "DBINDEX" the other, "DOCS."
start.cfm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Verity Fuel Pack Samples</TITLE>
</HEAD>
<H2>Pick which index you want to build</H2>
<P>Select the collection you want to populate :</P>
<FORM METHOD="POST" ACTION="index.cfm">
<INPUT TYPE=radio NAME=collection VALUE=DBINDEX checked> Message table from CF 2.0 Examples<BR>
<INPUT TYPE=radio NAME=collection VALUE=DOCINDEX> Documents in the web server root directory tree<BR><BR>
<INPUT TYPE=SUBMIT NAME=doindex VALUE="Populate">
</FORM>
<H3>Skip populating the collection, go right to<A HREF="search.cfm"> searching a collection</A></H3>
</BODY>
</HTML>
Now populate the collection you chose:
Index.cfm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Verity Custom Tag Tests </TITLE>
</HEAD>
<CFQUERY NAME="Messages" DATASOURCE="CF 2.0 Examples">
Select * from Messages </CFQUERY>
<BODY>
<CFIF #form.collection# IS "DBINDEX">
<CFX_INDEX
COLLECTION="DBINDEX"
ACTION="UPDATE"
TYPE="CUSTOM"
BODY="Body"
KEY="Message_ID"
TITLE="UserName"
QUERY="Messages">
<CFELSE>
<CFX_INDEX
COLLECTION="DOCS"
TYPE="PATH"
KEY="c:\inetpub\wwwroot"
URLPATH="http://127.0.0.1/"
EXTENSIONS=".htm, .html, .cfm, .cfml"
RECURSE="YES">
</CFIF>
<H2>Collection Successfully Generated</H2>
<H3><A HREF="search.cfm">Search the collection</A></H3>
</BODY>
</HTML>
With the collections populated, you can now offer a form for searching a collection:
Search.cfm
<!---search.cfm--->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>CFX_INDEX and CFX_SEARCH samples</TITLE>
</HEAD>
<BODY>
<H2>Search</H2>
<P><B>Select search type:</B></P>
<FORM METHOD="POST" ACTION="vfp_search.cfm"><P>
<INPUT TYPE=radio NAME=type VALUE=Simple checked> Simple<BR>
<INPUT TYPE=radio NAME=type VALUE=Explicit> Explicit<P>
<P><B>Select data source:</B></P>
<INPUT TYPE=radio NAME=source VALUE=DBINDEX checked> Messages Table<BR>
<INPUT TYPE=radio NAME=source VALUE=DOCS> Web doc root directory<P>
Search string: <INPUT TYPE=text NAME=searchstring SIZE=50><P>
<INPUT TYPE=SUBMIT NAME=search1 VALUE="Search"> <INPUT TYPE=reset VALUE="Reset">
</FORM>
</BODY>
</HTML>
The following example processes the search results.
vfp_search.cfm
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>Search output template</TITLE>
</HEAD>
<CFIF #form.source# IS "DBINDEX">
<CFSET #type# = "messages">
<CFELSE>
<CFSET #type# = "files">
</CFIF>
<BODY>
<CFX_SEARCH
NAME="Search1"
COLLECTION="#form.source#"
TYPE="#form.type#"
CRITERIA = "#form.searchstring#">
<H2>Search Results</H2>
<CFOUTPUT>
#Search1.RecordCount# #type# found out of #Search1.RecordsSearched# #type# searched.
</CFOUTPUT>
<HR NOSHADE>
<CFIF #form.source# IS "DBINDEX">
<CFOUTPUT QUERY="Search1">
<A HREF="cf_tag_verity_detail.cfm?ID=#Search1.KEY#"> Message #Search1.KEY# posted by #Search1.TITLE# </A> <BR>Score = #Search1.SCORE#<BR><BR>
</CFOUTPUT>
<CFELSE>
<CFOUTPUT QUERY="Search1">
<A HREF="#Search1.URL#">#Search1.Title#</A><BR>
</CFOUTPUT>
</CFIF>
<HR NOSHADE>
</BODY>
</HTML>
This template presents each individual message.
cf_tag_verity_detail.cfm
<CFQUERY NAME="MessageDetail" DATASOURCE="CF 2.0 Examples">
Select UserName, Subject, Body from Messages WHERE Message_ID = #ID# </CFQUERY>
<CFOUTPUT QUERY="MessageDetail">
<PRE>
Message #URL.ID# <BR>
Posted by: #MessageDetail.UserName# <BR>
Subject: #MessageDetail.Subject# <BR>
#MessageDetail.Body#
</PRE>
</CFOUTPUT>