Ask a Jedi: Paging within cfsearch?

Peter asks:

Whats the BEST way to page results from cfsearch?

I think my readers are being a bit pushy lately on “best” - I’m feeling the pressure. ;) Luckily this one is easy. The cfsearch tag allows for both a startrow and maxRows value. So to paginate, you would simply pass in startrow and set maxRows to startrow plus some arbitrary number for the number of results per page.

The only tricky bit is getting the total number of matches found. If you use the status attribute, like below:

<cfsearch collection="cfdocs" criteria="cf" name="results" startrow="5" maxrows="5" status="s">

You get a structure back that contains three keys: found, searched, and time. Found represents the total number of matches. You would want to use that for your paging.

p.s. Let me abuse my blog entry here and mention I added similar functionality to Seeker last night.

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.

Lafayette, LA