Issue #2454731 by amateescu: SQLite: Fix search\Tests\SearchRankingTest

8.0.x
Alex Pott 2015-04-01 12:13:09 +01:00
parent 144aa5813f
commit bd1620fbb4
5 changed files with 22 additions and 19 deletions

View File

@ -115,6 +115,7 @@ class Connection extends DatabaseConnection {
$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'));

View File

@ -165,11 +165,13 @@ class CommentStatistics implements CommentStatisticsInterface {
// 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),
),
);

View File

@ -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),

View File

@ -508,8 +508,12 @@ class SearchQuery extends SelectExtender {
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 @@ class SearchQuery extends SelectExtender {
// 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++;
}

View File

@ -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),
),
);