Components for script-based search, index, and collection

Attached to this blog entry are new CFCs that will allow you to perform collection operations (cfcollection, cfindex, and cfsearch) view script based CFCs. From the attached zip, simply store the components in your cfinstall\customtags\com\adobe\coldfusion folder. (Make a backup of base.cfc first!!) The test files are just that - tests. They mainly work with a collection I had called ‘test’ so you should not expect them to work as is. They are mainly there to provide you with an example. Here are a few examples…

Collection

<cfscript> c = new com.adobe.coldfusion.collection();

collections = c.list(); writedump(var=collections,label=”Collections, no engine”);

clist = c.categoryList(collection=”test”); writedump(var=clist,label=”Category list for collection test”);

//random name newname = “tempcollection_#replace(createUUID(), “-“,”_”,”all”)#”; c.create(collection=newname,path=server.coldfusion.rootdir & “/collections”);

writeoutput(“<p>Made #newname#</p>”);

collections = c.list(); writedump(var=collections,label=”Collections”);

c.delete(collection=newname);

collections = c.list(); writedump(var=collections,label=”Collections after I deleted the new one”);

c.optimize(collection=”test”); writeoutput(“Optimized test”); </cfscript> </code>

Index

<cfscript> //q is a query I made earlier, ditto for q2 idx = new com.adobe.coldfusion.index(); r = idx.refresh(collection="test",key="id",body="body",query=q,status=true); writeDump(var=r,label="refresh"); writeoutput("size of q2 - adding - #q2.recordCount#<br/>"); r = idx.update(collection="test",key="id",body="body",query=q2,status=true); writeDump(var=r,label="update"); r = idx.delete(collection="test",key=1,status=true); writeDump(var=r,label="delete"); r = idx.purge(collection="test",status=true); writeDump(var=r,label="purge"); </cfscript>

Search

<cfscript> mysearch = new com.adobe.coldfusion.search(); res = mysearch.search(criteria="cfabort",collection="cfdocs",maxrows=5,status="true"); writedump(var=res); writeoutput("<hr/>Done"); </cfscript>

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments