Created
January 26, 2017 09:02
-
-
Save szeidler/272560bd75968e4a0ed23b81853c0e9e to your computer and use it in GitHub Desktop.
Add a boost function, to prioritize recent content in Search API Solr queries. More recent articles will get boosted heavily, older ones less and less.
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
<?php | |
/** | |
* Boost published_at field to prioritize newer content. | |
* | |
* @see https://wiki.apache.org/solr/SolrRelevancyFAQ#How_can_I_boost_the_score_of_newer_documents | |
* Implements hook_search_api_solr_query_alter(). | |
*/ | |
function my_module_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query) { | |
// Boost more recently created articles. Boost the field with score +8 shrinking during 365 days. | |
$boost_field = 'ds_published_at'; | |
$call_args['params']['bf'][] = 'recip(ms(NOW/HOUR,' . $boost_field . '),3.16e-11,0.5,0.5)^800.0'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment