Creating a Verity collection from a database table?

I've been working on a document management project for a few months and have almost completed it.  I am at the stage where I need to create a search interface for my documents and have successfully done so using Verity.  I created a collection and then indexed it using the "Path" attribute.  This works well but I did run into some problems because I store information about the documents in a database and couldn't relate this information to the output of the Verity search results.  I read up on this and found an example in the CFDOCS online.  I'm not sure if I am understanding this right but it looks like I may be able to create a collection using my database table and also add a few custom fields in that I could use in my search as well.  

Here's my question:  Is it even possible to populate a collection using my database that would actually index the files on the server?  I need the search to look into the files content and not just the data I have saved in the database.

Can I add custom1 and custom2 attributes to the collection and will those be searchable and returned in the output?  

Here's what I have:
A table named Documents that has a DocumentID, Description, Filename, Full_Path, FolderID  
I think I could do a query to get all of the documents in the database and then output that around a cfindex but I tried that and it froze up my laptop.  I don't know if this will actually create a good index either.  The reason I want to do this is so that I can allow the filename and description that I have saved in the database to be searched and found along with the actual contents of the document.  Otherwise I have to create two seperate collections, one for the content and one for the database data.

Here's the code I tried if this makes sense:

 <cfquery name="getDocs" datasource="#application.datasource#">

<cfoutput query="getDocs">
     <p>#docname# #doctitle# #fullpath# #filename#p>



I'm not sure if I should try to make the key equal the primary key of the database table or the full path to the document?

Thanks for any advice on this one!
Who is Participating?
CFDevHeadConnect With a Mentor Commented:
First of all you shouldn't  to put CFOUTPUT around a CFINDEX is going to burn your system up every time. It will reindex the entire collection once for every record in the table. So if you have 100 records, it runs CFINDEX 100 times with no benefit!!!

Secondly, you can't mix TYPE=file with a QUERY. You're either indexing a query or a set of files.
The simple answer is to make 2 collections!!!
Index your files with the filename as the key.
Then index your query using the filename as the key.
Then run *2* CFSEARCHes using the filename as the criteria.

Good Luck
One more thing
Loop over the results to build a single summary string where the keys are the same.
Ike23Author Commented:
So this is totally wrong on the ColdFusion docs site?

Here's the part I'm referring to:

<cfquery name="bookquery"
    SELECT * FROM book where bookid='file'

<cfoutput query="bookquery">
    #url#,#description# <br>

<cfindex collection="snippets" action="update" type="file" query="bookquery" key="description" urlpath="url">


What I am trying to do is create a collection of the actual files but also include a few custom values that I can attach to each record and then also search.  This example does in fact lead me to believe that you can index a collection with a query with type="file".  

I did make a colleciton using the type="path" which works well and returns values based on a form search.  The problem is that it only searches the actual content and I want to be able to search for file name, author etc.  

Are you saying to create another collection using the database option and then do a cfsearch at the same time?

Thansk for your input,

Ike23Author Commented:
I just decided to create 2 seperate collections and search them at the same time.  Now that is working to my satisfaction I am going through each section to update the collections each time a document is added/edited/moved/deleted etc.  I almost have it all working except for the delete section.  I can get the File collection to delete the file from the collection but when I try to delete the record from the database collection it doesn't work.  I can still search for the file and it comes up but then there is no matching record in the database which causes an error.  Is there something I am missing here?  Here is what I am using:

      <cflock name="verity" timeout="60">
            <CFSET IndexCollection2 = "Database1">

No errors get thrown when I do this but I know that the record is still in the collection.  When I update the collection I use the Primary key field named DOCID.  Is that correct when I pass the value to  cfindex that it should look for the key and delete the data relating to that key?

Thanks for your help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.