diff --git Solr_Base_Query.php Solr_Base_Query.php index c555840..810474b 100644 --- Solr_Base_Query.php +++ Solr_Base_Query.php @@ -128,7 +128,8 @@ class Solr_Base_Query implements Drupal_Solr_Query_Interface { $this->filterstring = trim($filterstring); $this->parse_filters(); $this->available_sorts = $this->default_sorts(); - $this->parse_sortstring($sortstring); + $this->sortstring = trim($sortstring); + $this->parse_sortstring(); $this->base_path = $base_path; $this->id = ++self::$idCount; } @@ -236,9 +237,9 @@ class Solr_Base_Query implements Drupal_Solr_Query_Interface { $this->subqueries = array(); } - protected function parse_sortstring($sortstring) { + protected function parse_sortstring() { // Substitute any field aliases with real field names. - $sortstring = strtr(trim($sortstring), array_flip($this->field_map)); + $sortstring = strtr($this->sortstring, array_flip($this->field_map)); // Score is a special case - it's the default sort for Solr. if ('' == $sortstring) { $this->set_solrsort('score', 'asc'); @@ -270,10 +271,14 @@ class Solr_Base_Query implements Drupal_Solr_Query_Interface { public function set_available_sort($name, $sort) { // We expect non-aliased sorts to be added. $this->available_sorts[$name] = $sort; + // Re-parse the sortstring. + $this->parse_sortstring(); } public function remove_available_sort($name) { unset($this->available_sorts[$name]); + // Re-parse the sortstring. + $this->parse_sortstring(); } /** diff --git apachesolr_search.module apachesolr_search.module index 6700de8..4456607 100644 --- apachesolr_search.module +++ apachesolr_search.module @@ -207,6 +207,9 @@ function apachesolr_search_execute($keys, $filters, $solrsort, $base_path = '', apachesolr_search_add_facet_params($params, $query); apachesolr_search_add_boost_params($params, $query, $solr); + // Allow modules to alter the query prior to statically caching it. + // This can e.g. be used to add available sorts. + drupal_alter('apachesolr_current_query', $query); // Cache the built query. Since all the built queries go through // this process, all the hook_invocations will happen later