You are here

protected function SolrBaseQuery::parseSortString in Apache Solr Search 8

Same name and namespace in other branches
  1. 6.3 Solr_Base_Query.php \SolrBaseQuery::parseSortString()
  2. 7 Solr_Base_Query.php \SolrBaseQuery::parseSortString()
7 calls to SolrBaseQuery::parseSortString()
SolrBaseQuery::addFieldAliases in ./Solr_Base_Query.php
Handles aliases for field to make nicer URLs.
SolrBaseQuery::clearFieldAliases in ./Solr_Base_Query.php
SolrBaseQuery::removeAvailableSort in ./Solr_Base_Query.php
Removes an available sort.
SolrBaseQuery::setAvailableSort in ./Solr_Base_Query.php
Adds an available sort.
SolrBaseQuery::setAvailableSorts in ./Solr_Base_Query.php

... See full list

File

./Solr_Base_Query.php, line 558
This class allows you to make operations on a query that will be sent to Apache Solr. methods such as adding and removing sorts, remove and replace parameters, adding and removing filters, getters and setters for various parameters and more

Class

SolrBaseQuery

Code

protected function parseSortString() {

  // Substitute any field aliases with real field names.
  $sortstring = strtr($this->sortstring, $this->field_map);

  // Score is a special case - it's the default sort for Solr.
  if ('' == $sortstring || 'score desc' == $sortstring) {
    $this->solrsort['#name'] = 'score';
    $this->solrsort['#direction'] = 'desc';
    unset($this->params['sort']);
  }
  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->solrsort['#name'] = $matches[1];
      $this->solrsort['#direction'] = $matches[2];
      $this->params['sort'] = array(
        $sortstring,
      );
    }
  }
}