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>
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.
Archived Comments
Actually, it's not that confusing. I just can't seem to think about a real life example where you would use it. Maybe a multi-step search, that goes from broad to narrow. Just a thought...
Actually I needed this very function recently for a client who wanted the ability to refine search results. They have literally 1000's of documents / pages indexed, so this proved hugely useful.
:D
Hey man! Ray Camden isn't the only one who reads the ColdFusion documentation, ya know! Nah, just teasin! Thanks for the tip Raymond! :)
I've had to use similar approach when I used Lucene for product search on a custom built eCommerce apps that carries over 180k products. Eventually gave up on Lucene and went with full-text search leveraging the power of MSSQL 2008 and caching.
Might be fun to try SOLR now that this client is on dedicated 9.01 server.
Does MSSQL/Full Text support something like previousCriteria?
No, it doesn't, but I found a very fast way to process through the huge amount of products by utilizing
CONTAINSTABLE and then returning only the desired amount of products per page with ROW_NUMBER() OVER.
For the search within previous results, I just passed in the previously found items in a string and had that as the first filter inside the SQL query.
Super fast; both Verity (2009) and Lucene (2010) were left on the starting line by the time my current approach had already searched through several varchar(MAX) fields looking for the criteria in question and returned the first set of data on the page. We went from over 15000+ms and larger to 200-300ms on identical searches.
Interesting, thanks for sharing that Jaana.