diff --git Solr_Base_Query.php Solr_Base_Query.php index c555840..620642b 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,8 +237,11 @@ class Solr_Base_Query implements Drupal_Solr_Query_Interface { $this->subqueries = array(); } - protected function parse_sortstring($sortstring) { + public function parse_sortstring($sortstring = NULL) { // Substitute any field aliases with real field names. + if (empty($sortstring)) { + $sortstring = $this->sortstring; + } $sortstring = strtr(trim($sortstring), array_flip($this->field_map)); // Score is a special case - it's the default sort for Solr. if ('' == $sortstring) { diff --git apachesolr_search.module apachesolr_search.module index 6700de8..1d07084 100644 --- apachesolr_search.module +++ apachesolr_search.module @@ -207,6 +207,12 @@ 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); + + // Re-parse the sortstring. + $query->parse_sortstring(); // Cache the built query. Since all the built queries go through // this process, all the hook_invocations will happen later