Issue #893302 by jhodgdon, rayasa: Search ranking based on the factor 'number of comments' & 'No of Page Views' is broken.
parent
7dcaa39580
commit
3ea2e2cdae
|
@ -1041,10 +1041,11 @@ function comment_node_update_index(EntityInterface $node, $langcode) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_index().
|
||||
* Implements hook_cron().
|
||||
*/
|
||||
function comment_update_index() {
|
||||
// Store the maximum possible comments per thread (used for ranking by reply count)
|
||||
function comment_cron() {
|
||||
// Store the maximum possible comments per thread (used for node search
|
||||
// ranking by reply count).
|
||||
\Drupal::state()->set('comment.node_comment_statistics_scale', 1.0 / max(1, db_query('SELECT MAX(comment_count) FROM {comment_entity_statistics}')->fetchField()));
|
||||
}
|
||||
|
||||
|
@ -1557,8 +1558,8 @@ function comment_ranking() {
|
|||
'on' => "ces.entity_id = i.sid AND ces.entity_type = 'node' AND ces.field_id = 'node__comment'",
|
||||
),
|
||||
// Inverse law that maps the highest reply count on the site to 1 and 0 to 0.
|
||||
'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * CAST(:scale AS DECIMAL))',
|
||||
'arguments' => array(':scale' => \Drupal::state()->get('comment.node_comment_statistics_scale') ?: 0),
|
||||
'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * :scale)',
|
||||
'arguments' => array(':scale' => (float) \Drupal::state()->get('comment.node_comment_statistics_scale') ?: 0),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -83,10 +83,6 @@ class SearchRankingTest extends SearchTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
// Update the search index.
|
||||
$this->nodeSearch->getPlugin()->updateIndex();
|
||||
search_update_totals();
|
||||
|
||||
// Add a comment to one of the nodes.
|
||||
$edit = array();
|
||||
$edit['subject'] = 'my comment title';
|
||||
|
@ -98,22 +94,16 @@ class SearchRankingTest extends SearchTestBase {
|
|||
// Enable counting of statistics.
|
||||
\Drupal::config('statistics.settings')->set('count_content_views', 1)->save();
|
||||
|
||||
// Then View one of the nodes a bunch of times.
|
||||
// Manually calling statistics.php, simulating ajax behavior.
|
||||
$client = \Drupal::httpClient();
|
||||
$client->setConfig(array('curl.options' => array(CURLOPT_TIMEOUT => 10)));
|
||||
// Simulating content views is kind of difficult in the test. Leave that
|
||||
// to the Statistics module. So instead go ahead and manually update the
|
||||
// counter for this node.
|
||||
$nid = $nodes['views'][1]->id();
|
||||
global $base_url;
|
||||
$stats_path = $base_url . '/' . drupal_get_path('module', 'statistics'). '/statistics.php';
|
||||
for ($i = 0; $i < 5; $i ++) {
|
||||
$client->post($stats_path, array(), array('nid' => $nid))->send();
|
||||
}
|
||||
db_insert('node_counter')
|
||||
->fields(array('totalcount' => 5, 'daycount' => 5, 'timestamp' => REQUEST_TIME, 'nid' => $nid))
|
||||
->execute();
|
||||
|
||||
// @todo - comments and views are removed from the array since they are
|
||||
// broken in core. Those modules expected hook_update_index() to be called
|
||||
// even though it was only called on modules that implemented a search type.
|
||||
array_pop($node_ranks);
|
||||
array_pop($node_ranks);
|
||||
// Run cron to update the search index and comment/statistics totals.
|
||||
$this->cronRun();
|
||||
|
||||
// Test that the settings form displays the context ranking section.
|
||||
$this->drupalGet('admin/config/search/settings/manage/node_search');
|
||||
|
|
|
@ -118,6 +118,9 @@ function statistics_cron() {
|
|||
->execute();
|
||||
\Drupal::state()->set('statistics.day_timestamp', REQUEST_TIME);
|
||||
}
|
||||
|
||||
// Calculate the maximum of node views, for node search ranking.
|
||||
\Drupal::state()->set('statistics.node_counter_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -241,20 +244,13 @@ 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.
|
||||
'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * CAST(:scale AS DECIMAL))',
|
||||
'arguments' => array(':scale' => \Drupal::state()->get('statistics.node_counter_scale') ?: 0),
|
||||
'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * :scale)',
|
||||
'arguments' => array(':scale' => (float) \Drupal::state()->get('statistics.node_counter_scale') ?: 0),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_index().
|
||||
*/
|
||||
function statistics_update_index() {
|
||||
\Drupal::state()->set('statistics.node_counter_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_HOOK() for block templates.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue