title: Sort SOLR query by one field if date is between two dates, otherwise by different field
body: <p>I have 4 fields in my SOLR documents:</p>
  
  <ul>
  <li>price: float, indexed, stored</li>
  <li>special_price: float, indexed, stored</li>
  <li>special_price_from: date, indexed, stored</li>
  <li>special_price_to: date, indexed, stored</li>
  </ul>
  
  <p>I want to sort by <code>special_price</code> if current date is between <code>special_price_from</code> and <code>special_price_to</code>. If not, I want it sorted by <code>price</code>.</p>
  
  <p>As far as I understood, FunctionQueries are evaluated per document.</p>
  
  <p>I've tried different sort expressions, neither of them worked. I couldn't even get it to work without the timeframe:</p>
  
  <pre><code>sort=if(special_price,special_price,price) asc
  </code></pre>
  
  <p>or</p>
  
  <pre><code>sort=def(special_price,price) asc
  </code></pre>
  
  <p>or (with and without string literal)</p>
  
  <pre><code>sort=query($qq)+asc&amp;qq=if(special_price,"special_price","price")
  </code></pre>
  
  <p>Maybe I'm thinking too much in MySQL terms but I just can't figure it out.</p>
  
  <p>I'm using SOLR 3.6.2. </p>