4

I am using Search API solr on my site. To get better search results I would like to boost the relevance by the value of a certain numeric field. Say, all items have a field A, which is numeric. Now I want to boost the relevance of those itemes by the value of field a, so that, if As value is higher the relevance of the item becomes higher too. I have absolutely no idea how to do this. Maybe with

hook_search_api_solr_query_alter() 

But I did not find documentation how to use it. Please hint me in the right direction.

1 Answer 1

2

hook_apachesolr_query_alter($query) alter the query after it's prepared and cached.

As per example given in documentation which I found, you can use this hook in similar way to other query_alter hook. E.g -

function hook_apachesolr_query_alter($query) {
  //Adding one more filter.
  $query->addFilter("is_uid", 1);

  // Only search titles.
  $query->replaceParam('qf', 'label');
}

Find the documentation by clicking on the mentioned hook name by me.

EDITED--

Sorry for giving example of other hook of apache solr module. You can find documentation of your hook here hook_search_api_solr_query_alter().

You can find a small snippet for example of this hook like --

function hook_search_api_solr_query_alter(array &$call_args, SearchApiQueryInterface $query) {
  if ($query->getOption('foobar')) {
    $call_args['params']['foo'] = 'bar';
  }
}

Eric has wrote a nice article with example of this hook.

3
  • 1
    Her question refers to Search API solr module and not to Apachesolr module.
    – user5950
    Jul 15, 2013 at 16:47
  • @user5950 - I have edited the answer...thanks for pointing out.
    – RajeevK
    Jul 22, 2013 at 6:46
  • Use this to boost by a numeric field, where is_field_priority is the solr name for an indexed Drupal field. $call_args['params']['bf'][] = 'sum(1,product(2000,is_field_priority))'
    – user5950
    Dec 22, 2015 at 2:48

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.