function node_ranking
Same name in other branches
- 7.x modules/node/node.module \node_ranking()
- 9 core/modules/node/node.module \node_ranking()
- 10 core/modules/node/node.module \node_ranking()
Implements hook_ranking().
File
-
core/
modules/ node/ node.module, line 725
Code
function node_ranking() {
// Create the ranking array and add the basic ranking options.
$ranking = [
'relevance' => [
'title' => t('Keyword relevance'),
// Average relevance values hover around 0.15
'score' => 'i.relevance',
],
'sticky' => [
'title' => t('Content is sticky at top of lists'),
// The sticky flag is either 0 or 1, which is automatically normalized.
'score' => 'n.sticky',
],
'promote' => [
'title' => t('Content is promoted to the front page'),
// The promote flag is either 0 or 1, which is automatically normalized.
'score' => 'n.promote',
],
];
// Add relevance based on updated date, but only if it the scale values have
// been calculated in node_cron().
if ($node_min_max = \Drupal::state()->get('node.min_max_update_time')) {
$ranking['recent'] = [
'title' => t('Recently created'),
// Exponential decay with half life of 14% of the age range of nodes.
'score' => 'EXP(-5 * (1 - (n.created - :node_oldest) / :node_range))',
'arguments' => [
':node_oldest' => $node_min_max['min_created'],
':node_range' => max($node_min_max['max_created'] - $node_min_max['min_created'], 1),
],
];
}
return $ranking;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.