Indexing a file returned using a query

You can index an individual file using a query by retrieving a table row whose contents are a filename. In this case, the key specifies the column that contains the complete filename. The file is indexed using the cfindex tag as if it were a document under the web server root folder.

In the following example, the cfindex tag's type attribute has been set to file, and the specified key is the name of the column that contains the full path to the file and the filename.

To index a file specified by a query:

<cfquery name="getEmps" datasource="cfdocexamples">
SELECT * FROM EMPLOYEE WHERE EMP_ID = 1
</cfquery>
<cfindex 
   query="getEmps"
   collection="CodeColl"
   action="Update"
   type="file"
   key="Contract_File" 
   title="Contract_File"
   body="Emp_ID,FirstName,LastName,Contract_File">

To search and display the file:

  1. Create a ColdFusion page that contains the following content:
<!--- Output the record set.--->
<p>Your collection now includes the following items:</p>
<cfoutput query="getEmps">
<p>#Emp_ID# #FirstName# #LastName# #Contract_File#</p>
</cfoutput>
<cfsearch 
   collection="#Form.collname#"
   name="getEmps"
   criteria="#Form.Criteria#"
   maxrows = "100">

<!--- Output the file name contained in the record set. --->
<cfoutput>
Your search returned #getEmps.RecordCount# file(s).
</cfoutput>
<cfoutput query="getEmps">
<p><table>
   <tr><td>Title: </td><td>#Title#</td></tr>
   <tr><td>Score: </td><td>#Score#</td></tr>
   <tr><td>Key: </td><td>#Key#</td></tr>
   <tr><td>Summary: </td><td>#Summary#</td></tr>
   <tr><td>Custom 1:</td><td>#Custom1#</td></tr>
   <tr><td>Column list: </td><td>#ColumnList#</td></tr>
</table></p>
</cfoutput>

View comments in LiveDocs