title: Sum field and sort on Solr
body: <p>I'm implementing a grouped search in Solr. I'm looking for a way of summing one field and sort the results by this sum. With the following data example I hope it will be clearer.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
    [
      {
        "id" : 1,
        "parent_id" : 22,
        "valueToBeSummed": 3
      },
      {
        "id" : 2,
        "parent_id" : 22,
        "valueToBeSummed": 1
      },
      {
        "id" : 3,
        "parent_id" : 33,
        "valueToBeSummed": 1
      },
      {
        "id" : 4,
        "parent_id" : 5,
        "valueToBeSummed": 21
      }
    ]
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>If the search is made over this data I'd like to obtain</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
    [
      {
        "numFound": 1,
        "summedValue" : 21,
        "parent_id" : 5
      },
      {
        "numFound": 2,
        "summedValue" : 4,
        "parent_id" : 22
      },
      {
        "numFound": 1,
        "summedValue" : 1,
        "parent_id" : 33
      }
    ]
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Do you have any advice on this ?</p>