? .svn
? SolrPhpClient
? contrib/.svn
? contrib/apachesolr_image/.svn
? contrib/apachesolr_nodeaccess/.svn
? contrib/apachesolr_nodeaccess/tests/.svn
? contrib/apachesolr_og/.svn
? tests/.svn
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	30 Jun 2009 11:02:58 -0000
@@ -65,14 +65,14 @@ class Solr_Base_Query implements Drupal_
    * used for filter queries, e.g. array('#name' => 'uid', '#value' => 0)
    * for anonymous content.
    */
-  protected $fields;
+  protected $fields = array();
 
   /**
    * The complete filter string for a query.  Usually from $_GET['filters']
    * Contains name:value pairs for filter queries.  For example,
    * "type:book" for book nodes.
    */
-  protected $filterstring;
+  protected $filterstring = '';
 
   /**
    * A mapping of field names from the URL to real index field names.
@@ -87,19 +87,23 @@ class Solr_Base_Query implements Drupal_
   /**
    * The search keywords.
    */
-  protected $keys;
+  protected $keys = '';
 
   /**
    * The search base path.
    */
-  protected $base_path;
+  protected $base_path = '';
 
   /**
    * Apache_Solr_Service object
    */
   protected $solr;
 
-  protected $available_sorts;
+  protected $available_sorts = array();
+
+  protected $solrsort = '';
+
+  protected $extra_queryvalues = array();
 
   /**
    * @param $solr
@@ -123,11 +127,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 +238,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 +268,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'),
@@ -263,17 +277,28 @@ class Solr_Base_Query implements Drupal_
   }
 
   /**
+   * Set extra GET parameters that need to be preserved. Typically you'd pass in $_GET or $form_state['values'].
+   */
+  public function set_extra_queryvalues($params, $exclude = array('q', 'page', 'filters', 'solrsort')) {
+    $this->extra_queryvalues = array_diff_key($params, array_flip($exclude));
+  }
+
+  /**
    * Return filters and sort in a form suitable for a query param to url().
    */
   public function get_url_querystring() {
-    $querystring = '';
+    $queryvalues = $this->extra_queryvalues;
     if ($fq = $this->rebuild_fq(TRUE)) {
-      $querystring = 'filters='. rawurlencode(implode(' ', $fq));
+      $queryvalues['filters'] = implode(' ', $fq);
     }
     if ($this->solrsort) {
-      $querystring .= ($querystring ? '&' : '') .'solrsort='. rawurlencode($this->solrsort);
+      $queryvalues['solrsort'] = strtr($this->solrsort, array_flip($this->field_map));
+    }
+    $querystrings = array();
+    foreach ($queryvalues as $key => $value) {
+      $querystrings[] = "{$key}=" . rawurlencode(check_plain($value));
     }
-    return $querystring;
+    return implode('&', $querystrings);
   }
 
   public function get_fq() {
Index: apachesolr.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/apachesolr/apachesolr.module,v
retrieving revision 1.1.2.12.2.150
diff -u -p -r1.1.2.12.2.150 apachesolr.module
--- apachesolr.module	30 Jun 2009 10:57:24 -0000	1.1.2.12.2.150
+++ apachesolr.module	30 Jun 2009 11:02:58 -0000
@@ -970,10 +970,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;
+  }
 }
 
 /**
@@ -1460,6 +1465,17 @@ interface Drupal_Solr_Query_Interface {
   function get_path();
 
   /**
+   * Set extra values that will be added when calling get_url_querystring().
+   *
+   * @param $params
+   *   An array of parameters to be URL encoded. Typically $_GET.
+   * @param $exclude
+   *   An array of keys to exclude from $params.
+   * @return None.
+   */
+  function set_extra_queryvalues($params, $exclude = array('q', 'page', 'filters', 'solrsort'));
+
+ /**
    * Return any query string for use in the l function.
    *
    * @see l()
@@ -1474,12 +1490,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.106
diff -u -p -r1.1.2.6.2.106 apachesolr_search.module
--- apachesolr_search.module	30 Jun 2009 10:57:24 -0000	1.1.2.6.2.106
+++ apachesolr_search.module	30 Jun 2009 11:02:58 -0000
@@ -126,7 +126,7 @@ function apachesolr_search_search($op = 
       $solrsort = isset($_GET['solrsort']) ? $_GET['solrsort'] : '';
       $page = isset($_GET['page']) ? $_GET['page'] : 0;
       try {
-        $results = apachesolr_search_execute($keys, $filters, $solrsort, 'search/' . arg(1), $page);
+        $results = apachesolr_search_execute($keys, $filters, $solrsort, 'search/' . arg(1), $page, $_GET);
         return $results;
       }
       catch (Exception $e) {
@@ -184,21 +184,15 @@ 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();
-  }
+function apachesolr_search_execute($keys, $filters, $solrsort, $base_path = '', $page = 0, $extra_querystrings = array(), $caller = 'apachesolr_search') {
+
+  $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()'));
   }
+  $query->set_extra_queryvalues($extra_querystrings);
   // This is the object that does the communication with the solr server.
   $solr = apachesolr_get_solr();
   $params += apachesolr_search_basic_params($query);
