diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index 37ad89b..2d994fc 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -115,6 +115,7 @@ public static function open(array &$connection_options = array()) { $pdo->sqliteCreateFunction('if', array(__CLASS__, 'sqlFunctionIf')); $pdo->sqliteCreateFunction('greatest', array(__CLASS__, 'sqlFunctionGreatest')); $pdo->sqliteCreateFunction('pow', 'pow', 2); + $pdo->sqliteCreateFunction('exp', 'exp', 1); $pdo->sqliteCreateFunction('length', 'strlen', 1); $pdo->sqliteCreateFunction('md5', 'md5', 1); $pdo->sqliteCreateFunction('concat', array(__CLASS__, 'sqlFunctionConcat')); diff --git a/core/modules/comment/src/CommentStatistics.php b/core/modules/comment/src/CommentStatistics.php index f77a2c1..588c831 100644 --- a/core/modules/comment/src/CommentStatistics.php +++ b/core/modules/comment/src/CommentStatistics.php @@ -165,11 +165,13 @@ public function getRankingInfo() { // nodes. 'on' => "ces.entity_id = i.sid AND ces.entity_type = 'node' AND ces.field_name = 'comment'", ), - // Inverse law that maps the highest reply count on the site to 1 and 0 - // to 0. Note that the CAST here is necessary for PostgreSQL, because the - // PostgreSQL PDO driver sometimes puts values in as strings instead of - // numbers in complex expressions like this. - 'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * (CAST (:comment_scale AS DECIMAL(10, 4))))', + // Inverse law that maps the highest view count on the site to 1 and 0 + // to 0. Note that the ROUND here is necessary for PostgreSQL and SQLite + // in order to ensure that the :comment_scale argument is treated as + // a numeric type, because the PostgreSQL PDO driver sometimes puts + // values in as strings instead of numbers in complex expressions like + // this. + 'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * (ROUND(:comment_scale, 4)))', 'arguments' => array(':comment_scale' => \Drupal::state()->get('comment.node_comment_statistics_scale') ?: 0), ), ); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index d0a7bcf..59a2596 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -665,14 +665,8 @@ function node_ranking() { if ($node_min_max = \Drupal::state()->get('node.min_max_update_time')) { $ranking['recent'] = array( 'title' => t('Recently created'), - 'join' => array( - 'type' => 'LEFT', - 'table' => 'node_field_data', - 'alias' => 'nfd', - 'on' => 'nfd.nid = sid', - ), // Exponential decay with half life of 14% of the age range of nodes. - 'score' => 'EXP(-5 * (1 - (nfd.created - :node_oldest) / :node_range))', + 'score' => 'EXP(-5 * (1 - (n.created - :node_oldest) / :node_range))', 'arguments' => array( ':node_oldest' => $node_min_max['min_created'], ':node_range' => max($node_min_max['max_created'] - $node_min_max['min_created'], 1), diff --git a/core/modules/search/src/SearchQuery.php b/core/modules/search/src/SearchQuery.php index 4bd0a35..c1ecb48 100644 --- a/core/modules/search/src/SearchQuery.php +++ b/core/modules/search/src/SearchQuery.php @@ -508,8 +508,12 @@ public function addScore($score, $arguments = array(), $multiply = FALSE) { if ($multiply) { $i = count($this->multiply); // Modify the score expression so it is multiplied by the multiplier, - // with a divisor to renormalize. - $score = "(CAST (:multiply_$i AS DECIMAL(10,4))) * COALESCE(($score), 0) / (CAST (:total_$i AS DECIMAL(10,4)))"; + // with a divisor to renormalize. Note that the ROUND here is necessary + // for PostgreSQL and SQLite in order to ensure that the :multiply_* and + // :total_* arguments are treated as a numeric type, because the + // PostgreSQL PDO driver sometimes puts values in as strings instead of + // numbers in complex expressions like this. + $score = "(ROUND(:multiply_$i, 4)) * COALESCE(($score), 0) / (ROUND(:total_$i, 4))"; // Add an argument for the multiplier. The :total_$i argument is taken // care of in the execute() method, which is when the total divisor is // calculated. @@ -524,7 +528,7 @@ public function addScore($score, $arguments = array(), $multiply = FALSE) { // in the execute() method we can add arguments. while (($pos = strpos($score, 'i.relevance')) !== FALSE) { $pieces = explode('i.relevance', $score, 2); - $score = implode('((CAST (:normalization_' . $this->relevance_count . ' AS DECIMAL(10,4))) * i.score * t.count)', $pieces); + $score = implode('((ROUND(:normalization_' . $this->relevance_count . ', 4)) * i.score * t.count)', $pieces); $this->relevance_count++; } diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index 5d84cb9..57e8ffc 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -169,10 +169,12 @@ function statistics_ranking() { 'on' => 'node_counter.nid = i.sid', ), // Inverse law that maps the highest view count on the site to 1 and 0 - // to 0. Note that the CAST here is necessary for PostgreSQL, because - // the PostgreSQL PDO driver sometimes puts values in as strings - // instead of numbers in complex expressions like this. - 'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * (CAST (:statistics_scale AS DECIMAL(10,4))))', + // to 0. Note that the ROUND here is necessary for PostgreSQL and SQLite + // in order to ensure that the :statistics_scale argument is treated as + // a numeric type, because the PostgreSQL PDO driver sometimes puts + // values in as strings instead of numbers in complex expressions like + // this. + 'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * (ROUND(:statistics_scale, 4)))', 'arguments' => array(':statistics_scale' => \Drupal::state()->get('statistics.node_counter_scale') ?: 0), ), );