title: CakePHP 2.0 - get result counts with specific parameters from a certain result set
body: <p>I'm working on a search engine using CakePHP 2.0 and am having difficulty finding the most efficient way to get the result I'm wanting.</p>
  
  <p>Say I'm querying people and I get a set of 20 results with 5 age 20, 10 age 30 and 5 age 40.  In addition, 15 of these people have brown eyes, 3 have blue and 2 have green.  I want to find the most efficient way to get those specific counts.  I'll then display these results on the page so that users can see what's in the results with those parameters.  They will then be able to click on one of them to add that search parameter to the current query.</p>
  
  <p>This isn't something that I can store in a database or cache at all because each search could be different and could/will return different results.</p>
  
  <p>If I'm not explaining what I'm trying to do (this may be likely) there are several websites that do this.  Cars.com uses this method when searching for cars.  You search a generic search and then links on the side allow you to narrow your results.  These links include counts of the current result set that fall within the specific parameter.</p>
  
  <p>An idea has been to get the full result set and then parse through it generating the counts and this would work, but in my specific project I'm dealing with thousands of records and it seems like this could add additional load time to the page and/or strain on the server. </p>
  
  <p>Here's a visual example:
  <img src="https://i.stack.imgur.com/dBQC4.jpg" alt="visual example of the question/result I&#39;m trying to achieve"></p>