How to boost relevance of Search API solr with creation date? We have replaced Drupal's core search with SolR but we have noticed a recursiveness issue regarding the search results, for ex. when searching “executive committee”, documents created in 2006 and 2007 are listed before newer documents created in 2010. (http://www.etuc.org/search-page)

What we would like to do is to sort the articles by date and by relevance.

We have tried to alter this at the View level (date + Search:relevance) but it short circuits SolR.

We have looked at the search api settings and it seems that one cannot boost date field. Only fulltext fields are ‘boostable’ (?)

We have also found a few articles related to the subject:


http://www.metaltoad.com/blog/date-boosting-solr-drupal-search-results
How to boost relevance of Search API solr with the value of a certain field?


but they weren’t much help.

We are using Drupal 7, SolR 3 and the following modules


Search API 7.x-1.11
Search API autocomplete 7.x-1.0
Search facets 7.x-1.11
Search views 7.x-1.11
SolR search 7.x-1.4


Does anybody has an idea how to fix this issue?
Thank you very much in advance.
To do this (Drupal 7), one needs to implement the below hook:

hook_search_api_solr_query_alter(&amp;$call_args, SearchApiQueryInterface $query)


This hook can go in the theme or module layer.

Example code could be:

/**
 * Implements hook_search_api_solr_query_alter().
 *
 * @see https://www.drupal.org/node/2009760#find-out-field-id
 * @see https://www.drupal.org/project/search_api_solr/issues/2194055
 * @see https://www.metaltoad.com/blog/date-boosting-solr-drupal-search-results
 * @see https://www.drupal.org/forum/support/module-development-and-code-questions/2014-12-18/extending-search-api-solr-search-with
 * @see https://www.drupal.org/project/search_api_solr/issues/2392499
 * @see https://www.drupal.org/project/search_api/issues/1694698
 * @see https://books.google.com.au/books?id=othpBgAAQBAJ&amp;pg=PA157&amp;lpg=PA157&amp;dq=3.16e-11+solr
 */
function mytheme_search_api_solr_query_alter(&amp;$call_args, SearchApiQueryInterface $query) {
  // Boost more recently created content. This is taken directly from an
  // apachesolr query with +1 boost (+1 for every 100).
  $fields_names = $query-&gt;getIndex()-&gt;server()-&gt;getFieldNames($query-&gt;getIndex());
  if (isset($fields_names['created'])) {
    // If using node property 'created', get solr name of it  e.g. 'dm_created'.
    $created_field_name = $fields_names['created'];
    // @codingStandardsIgnoreStart
    // Field name version.
    // $created_field_name = $fields_names['field_date'];
    // @codingStandardsIgnoreEnd
    // Ensure '$call_args['params']['bf']' exists.
    if (!isset($call_args['params']['bf'])) {
      $call_args['params']['bf'] = [];
    }
    $call_args['params']['bf'][] = "recip(ms(NOW,{$created_field_name}),3.16e-11,0.5,0.5)^100.0";
  }
}