Created
January 10, 2012 08:14
-
-
Save hannesl/1587809 to your computer and use it in GitHub Desktop.
A Drupal search result ranking scheme for just the post date.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Implements of hook_ranking(). Copied from node_ranking(). | |
| */ | |
| function MYMODULE_ranking() { | |
| $ranking = array(); | |
| // Add ranking based on just the creation date (node_ranking() also uses modified | |
| // date). | |
| if ($node_cron_last = variable_get('node_cron_last', 0)) { | |
| $ranking['MYMODULE_recent'] = array( | |
| 'title' => t('Recently posted, ignore modification date'), | |
| // Exponential decay with half-life of 6 months, starting at last indexed node | |
| 'score' => 'POW(2.0, (n.created - :node_cron_last) * 6.43e-8)', | |
| 'arguments' => array(':node_cron_last' => $node_cron_last), | |
| ); | |
| } | |
| return $ranking; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In Drupal 7, you can use a number of different ranking schemes at config/search/settings to control the order of the search results. The "Post date" scheme provided by core also takes the modification date into account which may not be what you want. Put this hook in a module and you'll get a new scheme what ranks results on just the post date.