I'm trying to boost search results to give more relevancy to newly updated / created content. What I have tried is to use the following:

 * Implementation of hook search_api_solr_query_alter
function mml_search_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query) {
  // Boost by changed date. Fresher to top.
  $call_args['params']['freshness'] = 'recip(abs(ms(NOW/HOUR,ds_changed)),3.16e-11,10,1)';

But it doesn't seem to have any effect.

Any help would be appreciated.

Here is screenshot of solr admin side of the "field" Im trying to boost http://monosnap.com/image/A3c6WOGi71z0Smeke8tYgBbnoeNkyK

  • 1
    I could do with finding this out as well . I was wondering if in > admin > config > search > Search api > index > % > fields . If I was to change the created from type 'date' to 'string' that I'd then be able to add it to the Boost and weighting. I don't want to test this on a live site though.
    – Deejay
    Nov 11, 2014 at 12:40
  • 1
    @Tuomas_Leppänen have you had any joy with this issue and finding a solution.
    – Deejay
    Nov 19, 2014 at 15:17
  • 1
    @Deejay sorry but nope. Nov 20, 2014 at 15:36
  • 1
    looking at the arguments I'm receiving in my code for this hook; I haven't got a value for $call_args['params']['freshness'] in $call_args['params']['qf'] is where I get an array of values that list the weights for the boost.
    – Deejay
    Dec 4, 2014 at 10:45
  • 1
    As a work-around you could set up a sort based on change date and default to that, works for us.
    – Darvanen
    Dec 4, 2014 at 22:17

2 Answers 2


This module may be a solution https://www.drupal.org/project/search_api_sorts

Otherwise using you method above - According to this post http://www.metaltoad.com/blog/date-boosting-solr-drupal-search-results

then you need to add an extra []

$call_args['params']['freshness'][] = 'recip(abs(ms(NOW/HOUR,ds_changed)),3.16e-11,10,1)';

However after testing I still can get the result I want.

For example the value 3.16e-11,10 ; as far as I understand it means a year of milliseconds that gives a score of 10 inside that time span. and then decrease after.

For testing I used

call_args['params']['qf'][] = 'recip(abs(ms(NOW/HOUR,ds_changed)),86400000,21,1)';

which should give Posts added/changed on the day a score of 21 and then decreases daily.

Testing with 3 identical listings. And only title set at a boost rate over 1. I cannot get the articles to listing in date. order. Have i missed something obvious.


In hook_apachesolr_query_prepare,add ur indexed field with ur weightage using param bf.
This hook is similar to the query_alter but runs before the query is cached

Reference to parameters https://cwiki.apache.org/confluence/display/solr/Common+Query+Parameters

     * Prepare the query by adding parameters, sorts, etc.
     * This hook is invoked before the query is cached. The cached query is used
     * after the search such as for building facet and sort blocks, so parameters
     * added during this hook may be visible to end users.
     * This is otherwise the same as HOOK_apachesolr_query_alter(), but runs before
     * it.
     * @param object $query
     *  An object implementing DrupalSolrQueryInterface. No need for &.

function module_apachesolr_query_prepare(DrupalSolrQueryInterface $query) {
     watchdog("solrquery", '<pre>' . print_r( $query, true) . '</pre>');

I have used


bq: Boost Query: specifies a factor by which a term or phrase should be "boosted" in importance when considering a match.

Where solrquery obj results like that

   [bq] => Array
                    [0] => tm_display_name^40

Assuming that field is already indexed in our solr.

Use that hook. Then search for a content. In recent log message 'solrquery',check whether your field is added in bq

Have added the link for you reference. http://www.computerminds.co.uk/articles/boosting-solr-search-results-query-time

  • 1
    If it is an answer to the question. please add some description to it. Dec 5, 2014 at 12:14
  • 1
    @orchid thank you for the reply. We have this issue on Search API Solr (drupal.org/project/search_api_solr ) and not the Apache Solr Search module(drupal.org/project/apachesolr); so I'm not 100% sure of the relevance of this reply to our issue.
    – Deejay
    Dec 9, 2014 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.