function node_ranking in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/node.module \node_ranking()
- 7 modules/node/node.module \node_ranking()
- 9 core/modules/node/node.module \node_ranking()
Implements hook_ranking().
File
- core/
modules/ node/ node.module, line 597 - The core module that allows content to be submitted to the site.
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;
}