You are here

protected function Solr_Base_Query::parse_sortstring in Apache Solr Search 5.2

Same name and namespace in other branches
  1. 6 Solr_Base_Query.php \Solr_Base_Query::parse_sortstring()
  2. 6.2 Solr_Base_Query.php \Solr_Base_Query::parse_sortstring()
3 calls to Solr_Base_Query::parse_sortstring()
Solr_Base_Query::remove_available_sort in ./Solr_Base_Query.php
Solr_Base_Query::set_available_sort in ./Solr_Base_Query.php
make a sort available
Solr_Base_Query::__construct in ./Solr_Base_Query.php

File

./Solr_Base_Query.php, line 266

Class

Solr_Base_Query

Code

protected function parse_sortstring() {

  // Substitute any field aliases with real field names.
  $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');
  }
  else {

    // Validate and set sort parameter
    $fields = implode('|', array_keys($this->available_sorts));
    if (preg_match('/^(?:(' . $fields . ') (asc|desc),?)+$/', $sortstring, $matches)) {

      // We only use the last match.
      $this
        ->set_solrsort($matches[1], $matches[2]);
    }
  }
}