title: SOLR - Querying Facets, return N results per Facet
body: <p>I have a very large number of documents stored in a SOLR index. I would like to perform a query that returns the Facet counts for a specified field, and the first 100 documents for <strong>each Facet field</strong> returned.</p>
  
  <p>For example. Let's assume I have a bunch of books stored in my SOLR index.</p>
  
  <pre><code>{ name: "Book 1", genre: "Mystery" },
  { name: "Book 2", genre: "Science Fiction" },
  { name: "Book 3", genre: "Romance" },
  { name: "Book 4", genre: "Mystery" }
  </code></pre>
  
  <p>Now, I want to specify a Faceted query on a field, in this example, the book's genre. <code>facet=true&amp;facet.field=genre</code>. This search result may look something like:</p>
  
  <pre><code> "facet_fields":{
      "genre":[
         "Mystery",503322,
         "Science Fiction",40759,
         "Romance",23987
      ]
   }
  </code></pre>
  
  <p>This gives me the number of books matching each genre. If I were to add a <code>rows</code> parameter to my query, this would simply return to me the first N number of books that match the query. </p>
  
  <p>However, I want to go one step further. I want SOLR to return to me the <strong>first 100 books of each genre</strong> that match my query. This means that, since 3 facet fields were returned (Mystery, Science Fiction, and Romance), this search might return up to 300 documents. </p>
  
  <p>If possible, I would like this all to be executed within a single query. Am I able to do so? Do I need to query SOLR multiple times in order to get what I am looking for? If so, what is the recommended approach to get what I am looking for? </p>
  
  <p>I'm fairly new to SOLR and just trying to get a grasp on what SOLR is and isn't capable of. </p>