#296624 by Damien Tournoud: fix do_search() queries (that are bad and fail on PostgreSQL).

From: Damien Tournoud <damien@tournoud.net>


---

 modules/node/node.module     |    6 +++---
 modules/search/search.module |    6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)


diff --git modules/node/node.module modules/node/node.module
index 422ab62..8efd20a 100644
--- modules/node/node.module
+++ modules/node/node.module
@@ -1333,13 +1333,13 @@ function node_search($op = 'search', $keys = NULL) {
         $total = 1;
         $arguments2 = array();
         $join2 = '';
-        $select2 = 'i.relevance AS calculated_score';
+        $select2 = 'SUM(i.relevance) AS calculated_score';
       }
       else {
         $total = $rankings['total'];
         $arguments2 = $rankings['arguments'];
         $join2 = implode(' ', $rankings['join']);
-        $select2 = '('. implode(' + ', $rankings['score']) .') AS calculated_score';
+        $select2 = 'SUM('. implode(' + ', $rankings['score']) .') AS calculated_score';
       }
 
       // Do search.
@@ -1405,7 +1405,7 @@ function node_ranking() {
     $ranking['recent'] = array(
       'title' => t('Recently posted'),
       // Exponential decay with half-life of 6 months, starting at last indexed node
-      'score' => '(POW(2, GREATEST(n.created, n.changed) - %d) * 6.43e-8)',
+      'score' => '(POW(2.0, GREATEST(n.created, n.changed) - %d) * 6.43e-8)',
       'arguments' => array($node_cron_last),
     );
   }
diff --git modules/search/search.module modules/search/search.module
index 2e4c4ef..909c953 100644
--- modules/search/search.module
+++ modules/search/search.module
@@ -905,7 +905,7 @@ function _search_parse_query(&$word, &$scores, $not = FALSE) {
  * @param $columns2
  *   (optional) Inserted into the SELECT pat of the second query. Must contain
  *   a column selected as 'calculated_score'.
- *   defaults to 'i.relevance AS calculated_score'
+ *   defaults to 'SUM(i.relevance) AS calculated_score'
  *
  * @param $join2
  *   (optional) Inserted into the JOIN par of the second SQL query.
@@ -923,7 +923,7 @@ function _search_parse_query(&$word, &$scores, $not = FALSE) {
  *
  * @ingroup search
  */
-function do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arguments1 = array(), $columns2 = 'i.relevance AS calculated_score', $join2 = '', $arguments2 = array(), $sort_parameters = 'ORDER BY calculated_score DESC') {
+function do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arguments1 = array(), $columns2 = 'SUM(i.relevance) AS calculated_score', $join2 = '', $arguments2 = array(), $sort_parameters = 'ORDER BY calculated_score DESC') {
   $query = search_parse_query($keywords);
 
   if ($query[2] == '') {
@@ -955,7 +955,7 @@ function do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arguments1
   if (!$normalize) {
     return array();
   }
-  $columns2 = str_replace('i.relevance', '(' . (1.0 / $normalize) . ' * SUM(i.score * t.count))', $columns2);
+  $columns2 = str_replace('i.relevance', '(' . (1.0 / $normalize) . ' * i.score * t.count)', $columns2);
 
   // Build query to retrieve results.
   $select = "SELECT i.type, i.sid, $columns2 FROM {search_index} i $join $join2 WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d";
