Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.152
diff -u -p -r1.1.2.12.2.152 apachesolr.module
--- apachesolr.module	1 Jul 2009 22:57:55 -0000	1.1.2.12.2.152
+++ apachesolr.module	1 Jul 2009 23:45:26 -0000
@@ -589,8 +589,8 @@ function apachesolr_block($op = 'list', 
         $new_query = clone $query;
         foreach ($sorts as $type => $sort) {
           $new_sort = isset($solrsorts[$type]) ? $solrsorts[$type] == 'asc' ? 'desc' : 'asc' : $sort['default'];
-          $new_query->set_solrsort($type == "relevancy" ? '' : "{$type} {$new_sort}");
-          $active = isset($solrsorts[$type]) || ($type == "relevancy" && !$solrsorts);
+          $new_query->set_solrsort($type == "score" ? '' : "{$type} {$new_sort}");
+          $active = isset($solrsorts[$type]) || ($type == "score" && !$solrsorts);
           $direction = isset($solrsorts[$type]) ? $solrsorts[$type] : '';
           $sort_links[$type] = array(
             'name' => $sort['name'],
@@ -977,10 +977,15 @@ function apachesolr_modify_query(&$query
     $function_name = $module . '_apachesolr_modify_query';
     $function_name($query, $params, $caller);
   }
+  // TODO: The query object should hold all the params.
   // Add array of fq parameters.
   if ($query && ($fq = $query->get_fq())) {
     $params['fq'] = $fq;
   }
+  // Add sort if present.
+  if ($query && ($sort = $query->get_solrsort())) {
+    $params['sort'] = $sort;
+  }
 }
 
 /**
@@ -1481,12 +1486,15 @@ interface Drupal_Solr_Query_Interface {
   /**
    * Set the solrsort.
    *
-   * @param string raw string to set the sort to
+   * @param $sortstring
+   *  Raw string to set the sort to - optionally use aliased field names.
    */
   function set_solrsort($sortstring);
 
   /**
    * Get the solrsort.
+   *
+   * Returns the non-urlencode, non-aliased sort field and direction
    */
   function get_solrsort();
 
Index: apachesolr_search.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr_search.module,v
retrieving revision 1.1.2.6.2.108
diff -u -p -r1.1.2.6.2.108 apachesolr_search.module
--- apachesolr_search.module	1 Jul 2009 22:57:55 -0000	1.1.2.6.2.108
+++ apachesolr_search.module	1 Jul 2009 23:45:26 -0000
@@ -185,20 +185,14 @@ function apachesolr_search_view($type = 
  * @throws Exception
  */
 function apachesolr_search_execute($keys, $filters, $solrsort, $base_path = '', $page = 0, $caller = 'apachesolr_search') {
-  // Validate sort parameter
-  // TODO: move this to the query class.
-  if (strlen($solrsort) && preg_match('/^([a-z0-9_]+ (asc|desc)(,)?)+$/i', $solrsort)) {
-    $params['sort'] = $solrsort;
-  }
-  else {
-    $solrsort = '';
-    $params = array();
-  }
+
+  $params = array();
   // This is the object that knows about the query coming from the user.
   $query = apachesolr_drupal_query($keys, $filters, $solrsort, $base_path);
   if (empty($query)) {
     throw new Exception(t('Could not construct a Solr query in function apachesolr_search_search()'));
   }
+
   // This is the object that does the communication with the solr server.
   $solr = apachesolr_get_solr();
   $params += apachesolr_search_basic_params($query);
@@ -832,7 +826,7 @@ function apachesolr_search_form_search_s
     $keys = str_replace('+', '%2B', $keys);
   }
   if (!empty($fv['apachesolr_search']['retain-filters']) && $fv['apachesolr_search']['querystring']) {
-    $querystring = $fv['apachesolr_search']['querystring'] . '&retain-filters';
+    $querystring = $fv['apachesolr_search']['querystring'] . '&retain-filters=1';
   }
   $form_state['redirect'] = array($base . $keys, $querystring);
   if ($keys == '' && $querystring == '') {
Index: Solr_Base_Query.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/Solr_Base_Query.php,v
retrieving revision 1.1.4.38
diff -u -p -r1.1.4.38 Solr_Base_Query.php
--- Solr_Base_Query.php	30 Jun 2009 10:57:23 -0000	1.1.4.38
+++ Solr_Base_Query.php	1 Jul 2009 23:45:26 -0000
@@ -123,11 +123,11 @@ class Solr_Base_Query implements Drupal_
     $this->solr = $solr;
     $this->keys = trim($keys);
     $this->filterstring = trim($filterstring);
-    $this->solrsort = trim($sortstring);
-    $this->base_path = $base_path;
-    $this->id = ++self::$idCount;
     $this->parse_filters();
     $this->available_sorts = $this->default_sorts();
+    $this->set_solrsort($sortstring);
+    $this->base_path = $base_path;
+    $this->id = ++self::$idCount;
   }
 
   function __clone() {
@@ -234,7 +234,17 @@ class Solr_Base_Query implements Drupal_
   }
 
   public function set_solrsort($sortstring) {
-    $this->solrsort = trim($sortstring);
+    // Validate sort parameter
+    $fields = implode('|', array_keys($this->available_sorts));
+    // Substitute any field aliases with real field names.
+    $sortstring = strtr(trim($sortstring), $this->field_map);
+    // Score is a special case - it's the default sort.
+    if ('score asc' == $sortstring) {
+      $sortstring = '';
+    }
+    if (('' == $solrsort) || preg_match('/^(('. $fields .') (asc|desc),?)+$/', $solrsort)) {
+      $this->solrsort = $sortstring;
+    }
   }
 
   public function get_solrsort() {
@@ -254,7 +264,7 @@ class Solr_Base_Query implements Drupal_
    */
   protected function default_sorts() {
     return array(
-      'relevancy' => array('name' => t('Relevancy'), 'default' => 'asc'),
+      'score' => array('name' => t('Relevancy'), 'default' => 'asc'),
       'sort_title' => array('name' => t('Title'), 'default' => 'asc'),
       'type' => array('name' => t('Type'), 'default' => 'asc'),
       'sort_name' => array('name' => t('Author'), 'default' => 'asc'),
