protected function SolrBaseQuery::parseSortString in Apache Solr Search 7
Same name and namespace in other branches
- 8 Solr_Base_Query.php \SolrBaseQuery::parseSortString()
- 6.3 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
File
- ./
Solr_Base_Query.php, line 599 - 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
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 = array_keys($this->available_sorts);
// Loop through available sorts and escape them, to allow for function sorts like geodist() in the preg_match() below
foreach ($fields as $key => $field) {
$fields[$key] = preg_quote($field);
}
// Implode the escaped available sorts together, then preg_match() against the sort string
$fields = implode('|', $fields);
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,
);
}
else {
return FALSE;
}
}
}