function node_ranking in Drupal 7
Same name and namespace in other branches
- 8 core/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
- modules/
node/ node.module, line 1759 - The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.
Code
function node_ranking() {
// Create the ranking array and add the basic ranking options.
$ranking = array(
'relevance' => array(
'title' => t('Keyword relevance'),
// Average relevance values hover around 0.15
'score' => 'i.relevance',
),
'sticky' => array(
'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' => array(
'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 creation or changed date.
if ($node_cron_last = variable_get('node_cron_last', 0)) {
$ranking['recent'] = array(
'title' => t('Recently posted'),
// Exponential decay with half-life of 6 months, starting at last indexed node
'score' => 'POW(2.0, (GREATEST(n.created, n.changed) - :node_cron_last) * 6.43e-8)',
'arguments' => array(
':node_cron_last' => $node_cron_last,
),
);
}
return $ranking;
}