ColdFusion and Verity Tip - Getting results found when paging

I was doing a code review this morning when I found this little gem:

<CFSEARCH NAME="pariscontactsTotal" COLLECTION="#collection#" TYPE="#searchType#" CRITERIA="#search#">

<CFSEARCH NAME=”pariscontacts” COLLECTION=”#collection#” TYPE=”#searchType#” CRITERIA=”#search#” STARTROW=”#startrow#” MAXROWS=”#itemsPerPage#”> </code>

So why the duplicate searches? They wanted to return a page of data, but also tell the user how many total matches were returned. This is far easier in ColdFusion 7 and higher. If you add the “status” attribute to your CFSEARCH tag, you can a structure back that contains keys for: Found (how many total found, even if you paginate the results), Searched (total number of records in the collection), and Time (time it took to search).

They could get rid of that first cfsearch and just do this:

<CFSEARCH NAME="pariscontacts" COLLECTION="#collection#" TYPE="#searchType#" CRITERIA="#search#" STARTROW="#startrow#" MAXROWS="#itemsPerPage#" status="result">

I’d name the client - but I’d like to get paid. ;) I will point something they did that was very good (and something I forget to do from time to time). Before searching, they run the search through verityClean first. A friend of mine had a site that didn’t do this - but as he owes me beer, I won’t name him either. ;)

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