diff --git a/apachesolr_views.module b/apachesolr_views.module index e2cac8d..288d84a 100644 --- a/apachesolr_views.module +++ b/apachesolr_views.module @@ -1,4 +1,5 @@ set_solrsort($sort, $order, true); + } + } +} \ No newline at end of file diff --git a/apachesolr_views_query.inc b/apachesolr_views_query.inc index f1da41d..36cd860 100644 --- a/apachesolr_views_query.inc +++ b/apachesolr_views_query.inc @@ -1,4 +1,5 @@ $field) { if (!empty($field['sort'])) { + + // TODO: Isolate, determine when to skip + + $skip = false; + switch ($field_name) { + case 'title': + case 'name': + $field_name = 'sort_'.$field_name; + break; + } + if ($skip === true) continue; + $this->_available_sorts[$field_name] = array( - 'name' => $field['title'], + 'title' => $field['title'], 'default' => 'asc', // TODO: make this part of the handler def? So it will be in the Views data definition ); } @@ -268,8 +281,7 @@ class apachesolr_views_query extends views_plugin_query implements Drupal_Solr_Q // add in the fields. These fields include the necessary fields. $this->_params['fl'] = implode(',', $this->_used_fields); - // build up the sorts here - $this->_params['sort'] = implode(',', $this->get_solrsort()); + $this->_params['sort'] = implode(' ', $this->get_solrsort()); // query template handling if (!empty($this->_query_template)) { @@ -461,12 +473,22 @@ class apachesolr_views_query extends views_plugin_query implements Drupal_Solr_Q * * @param $single If TRUE, the results will only be sorted by this order. */ - public function add_sort($field, $order, $single = FALSE) { + public function add_sort($field, $order, $single = TRUE) { if ($single) { $this->_sorts = array(); } - // don't need drupal_strtolower, this isn't a UTF-8 string - $this->_sorts[] = $field . ' ' . strtolower($order); + + switch ($field) { + case 'title': + case 'name': + $field = 'sort_'.$field; + break; + } + + $this->_sorts[] = array( + '#name' => $field, + '#direction' => $order + ); } /** @@ -722,6 +744,11 @@ class apachesolr_views_query extends views_plugin_query implements Drupal_Solr_Q $query_values[$field] = $value; } + $sort = $this->get_solrsort(); + if (!empty($sort)) { + $query_values['solrsort'] = implode(' ', $sort); + } + return $query_values; } @@ -745,7 +772,25 @@ class apachesolr_views_query extends views_plugin_query implements Drupal_Solr_Q * array keyed with name => direction */ function get_solrsort() { - return $this->_sorts; + $sorts = $this->_sorts; + + if (empty($sorts)) { + return array( + '#name' => 'score', + '#direction' => 'desc', + ); + } + + $first_sort = array_shift($sorts); + $sort_arr = array(); + foreach($sorts as $sort) { + $sort_arr[] = implode(' ', $sort); + } + return array( + '#name' => $first_sort['#name'], + '#direction' => $first_sort['#direction']. + (count($sort_arr) > 0 ? ','.implode(',', $sort_arr) : ''), + ); } /**