title: Alternate score-based sorting for Solr Grouping
body: <p>Currently, solr grouping (<a href="http://wiki.apache.org/solr/FieldCollapsing" rel="nofollow">http://wiki.apache.org/solr/FieldCollapsing</a>) sorts groups <strong><em>"by the score of the top document within each group"</em></strong>. E.g.</p>
  
  <pre><code>[...]
  "groups":[{
      "groupValue":"81cb63020d0339adb019a924b2a9e0c2",
      "doclist":{"numFound":9,"start":0,"maxScore":4.729042,"docs":[
          {
            "id":"7481df771afe39fab368ce19dfeeb528",
            [...],
            "score":4.729042},
          {
            "id":"c879e95b5f16343dad8b1248133727c2",
            [...],
            "score":4.6635237},
          {
            "id":"485b9aec90fd3ef381f013c51ab6a4df",
            [...],
            "score":4.347174}]
      }},
  [...]
  </code></pre>
  
  <p>Is there an out-of-the-box way to instead sort groups by the sum of the scores of the documents within each group? E.g.</p>
  
  <pre><code>[...]
  "groups":[{
      "groupValue":"81cb63020d0339adb019a924b2a9e0c2",
      "doclist":{"numFound":9,"start":0,"scoreSum":13.739738,"docs":[
          {
            "id":"7481df771afe39fab368ce19dfeeb528",
            [...],
            "score":4.729042},
          {
            "id":"c879e95b5f16343dad8b1248133727c2",
            [...],
            "score":4.6635237},
          {
            "id":"485b9aec90fd3ef381f013c51ab6a4df",
            [...],
            "score":4.347174}]
      }},
  [...]
  </code></pre>
  
  <p>With the release of sorting by Function Query (<a href="https://issues.apache.org/jira/browse/SOLR-1297" rel="nofollow">https://issues.apache.org/jira/browse/SOLR-1297</a>), it seems that there should be a way to use the sum() function (<a href="http://wiki.apache.org/solr/FunctionQuery" rel="nofollow">http://wiki.apache.org/solr/FunctionQuery</a>). But it's not quite close enough since the "score" field is not part of the documents.</p>
  
  <p>I feel like I'm close but I'm missing some obvious piece. I'm using Solr 3.5 .</p>