4

According to this, search results are ordered by relevance score. How can I override this? I want our results sorted by created date. I'm not talking about allowing users to sort by different fields, just the default order of results returned by apache solr.

5

This requires a custom modules where you implement a hook provided by apachesolr. There are several options but hook_apachesolr_modify_query(&$query, &$params, $caller) works as well as any.

You can modify the $query:

$query->set_solrsort($field_name, $direction); 

Or you can modify the $params:

$params['sort'] = "$field_name $direction";
| improve this answer | |
  • 1
    Since apachesolr-7.x-1.0-beta6 the hook changed to hook_apachesolr_query_alter($query) – Cristian Romanescu Mar 18 '14 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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