Did you know - previousCriteria and cfsearch

Here is a little feature I don’t see folks use too often, and it wasn’t actually working right for Solr in ColdFusion 9.0 (but corrected in 9.0.1), but did you know that it was possible to perform a search within the results of a previous search using ColdFusion’s Solr integration? (Technically this is also possible with Verity, but it’s best we ignore this as it doesn’t have much a life expectancy anymore in ColdFusion.)

In simplest terms, providing previousCriteria to the cfsearch tag will perform a “search within a search”, so if searching for food, for example, returned 100 results out a possible 1000, doing a second search for beer and using previousCriteria=”food” will return a number smaller.

Here is an incredibly simple example:

<cfsearch collection="cfdocs" criteria="cfsearch" name="results"> <cfoutput>Search for coldfusion: Returned #results.recordCount# results.<p/></cfoutput>

<cfsearch collection=”cfdocs” criteria=”solr” previouscriteria=”cfsearch” name=”results”> <cfoutput>Search for cffeed within coldfusion: Returned #results.recordCount# results.<p/></cfoutput>

<cfsearch collection=”cfdocs” criteria=”solr” name=”results”> <cfoutput>Search for cffeed by itself: Returned #results.recordCount# results.<p/></cfoutput> </code>

In this example my initial search is for cfsearch itself (I’m searching the ColdFusion docs so hopefully that makes sense). I then search for solr and provide cfsearch as the previousCriteria. As a final test, I search for solr by itself. My results were:

Search for coldfusion: Returned 39 results.
Search for cffeed within coldfusion: Returned 7 results.
Search for cffeed by itself: Returned 24 results.

Nice little feature, and interesting to use, but it seems like something you don't encounter in the wild too much. I wonder if it confuses users too much? Either way - hope this little tidbit helps.

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 https://www.raymondcamden.com