Commit 20295998 authored by Dries's avatar Dries

- Patch #296624 by Damien Tournoud: made search work on PostgreSQL.

parent 99afbc53
......@@ -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)),
),
);
......
......@@ -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),
);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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)),
),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment