diff options
author | Dries Buytaert <dries@buytaert.net> | 2008-12-02 21:24:34 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2008-12-02 21:24:34 +0000 |
commit | 20295998e7a14ff708a33572e860e0587aaa82c3 (patch) | |
tree | e6ea9c7237bdf668f2580d9039dbe03f0b04bc73 /modules | |
parent | 99afbc53a736ba30b294ed62611767345fe8c3dd (diff) | |
download | brdo-20295998e7a14ff708a33572e860e0587aaa82c3.tar.gz brdo-20295998e7a14ff708a33572e860e0587aaa82c3.tar.bz2 |
- Patch #296624 by Damien Tournoud: made search work on PostgreSQL.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/comment.module | 2 | ||||
-rw-r--r-- | modules/node/node.module | 8 | ||||
-rw-r--r-- | modules/search/search.module | 8 | ||||
-rw-r--r-- | modules/search/search.test | 3 | ||||
-rw-r--r-- | modules/statistics/statistics.module | 2 |
5 files changed, 13 insertions, 10 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module index d3f327bbc..a72100743 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -2117,7 +2117,7 @@ function comment_ranking() { 'title' => t('Number of comments'), 'join' => 'LEFT JOIN {node_comment_statistics} node_comment_statistics ON node_comment_statistics.nid = i.sid', // Inverse law that maps the highest reply count on the site to 1 and 0 to 0. - 'score' => '2.0 - 2.0 / (1.0 + node_comment_statistics.comment_count * %f)', + 'score' => '2.0 - 2.0 / (1.0 + node_comment_statistics.comment_count * CAST(%f AS DECIMAL))', 'arguments' => array(variable_get('node_cron_comments_scale', 0)), ), ); diff --git a/modules/node/node.module b/modules/node/node.module index bf528cdf9..7204e9f2a 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1229,7 +1229,7 @@ function _node_rankings() { } // Add the rankings weighted score multiplier value, handling NULL gracefully. - $rankings['score'][] = '%f * COALESCE(('. $values['score'] .'), 0)'; + $rankings['score'][] = 'CAST(%f AS DECIMAL) * COALESCE(('. $values['score'] .'), 0)'; // Add the the administrator's weighted score multiplier value for this ranking. $rankings['total'] += $node_rank; @@ -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 a/modules/search/search.module b/modules/search/search.module index 797254982..2b51c6925 100644 --- a/modules/search/search.module +++ b/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,12 +955,12 @@ 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"; $count_select = "SELECT COUNT(*) FROM ($select) n1"; - $arguments = array_merge($arguments2, $arguments1, array($query[4])); + $arguments = array_values(array_merge($arguments2, $arguments1, array($query[4]))); // Do actual search query $result = pager_query("$select $sort_parameters", 10, 0, $count_select, $arguments); diff --git a/modules/search/search.test b/modules/search/search.test index 849964dbc..a99d1e00d 100644 --- a/modules/search/search.test +++ b/modules/search/search.test @@ -303,6 +303,9 @@ class SearchRankingTestCase extends DrupalWebTestCase { node_update_index(); search_update_totals(); + // Refresh variables after the treatment. + $this->refreshVariables(); + // Add a comment to one of the nodes. $edit = array('subject' => 'my comment title', 'comment' => 'some random comment'); $this->drupalGet('comment/reply/' . $nodes['comments'][1]->nid); diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 2bafc54bf..59604577d 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -340,7 +340,7 @@ function statistics_ranking() { 'title' => t('Number of views'), 'join' => 'LEFT JOIN {node_counter} node_counter ON node_counter.nid = i.sid', // Inverse law that maps the highest view count on the site to 1 and 0 to 0. - 'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * %f)', + 'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * CAST(%f AS DECIMAL))', 'arguments' => array(variable_get('node_cron_views_scale', 0)), ), ); |