How do you change the default sort in apachesolr? I've been trying to get this figured out for a couple days now, and I feel like I'm close, but as of yet no cigar. I need to make the apache solr search on the site I'm working on to have two sorts, 'created' and 'score'. The default search sort is score, but I need to change it to created.

I've got as far as changing the default itself, but then change is added unconditionally, so obviously it will always occur over score. Do I have to rebuild all the URLs to use arg, or is there an easier way? Here's my code:

Note: there's some code to remove some filters, but that's not related to the problem. I included them just in case.

   function myhook_apachesolr_prepare_query(&amp;$query, &amp;$params) {
     // Remove sorts
     $query-&gt;remove_available_sort('type');
     $query-&gt;remove_available_sort('sort_title');
     $query-&gt;remove_available_sort('sort_name');
     // Rename/Reorder sorts
     $query-&gt;remove_available_sort('created');
     $query-&gt;remove_available_sort('score');
     $query-&gt;set_available_sort('created', array('title' =&gt; t('Most Recent'), 'default' =&gt;     'desc'));
     $query-&gt;set_available_sort('score', array('title' =&gt; t('Most Relevant'), 'default' =&gt; 'asc'));

     // Change the default sort to by date
     $query-&gt;set_solrsort('created', 'desc');
   }
You can implement hook_apachesolr_query_alter() and add new sort criteria as below


/**
 * Implements hook_apachesolr_query_alter().
 */
function my_module_apachesolr_query_alter($query) {
  $query->addParam('sort', 'ss_date_field asc');
}