title: Drupal 7 sort search results by relevancy
body: <p>In my module I have <a href="https://stackoverflow.com/questions/8575289/extending-drupal-7-search">this</a> implementation where I have a <a href="http://api.drupal.org/api/drupal/modules--search--search.api.php/function/hook_search_execute/7" rel="nofollow noreferrer"><code>hook_search_execute()</code></a> function which can be used for rewriting/extending default Drupal search. This function calls for <a href="http://api.drupal.org/api/drupal/modules--search--search.extender.inc/function/SearchQuery%3A%3AexecuteFirstPass/7" rel="nofollow noreferrer"><code>executeFirstPass()</code></a> method and adds to the query the following <code>$first-&gt;addExpression('SUM(i.score * t.count)', 'calculated_score');
  </code></p>
  
  <p>When I'm trying to add my sorting as following <code>$query-&gt;orderBy('calculated_score', 'ASC');</code>, I have an error.</p>
  
  <p>However if I add <code>$query-&gt;orderBy('n.title', 'ASC');</code> or <code>$query-&gt;orderBy('n.created', 'ASC');</code> everything is fine and is sorting as it should be.</p>
  
  <p>Does anyone have any ideas why this is happens?</p>