You are here

public function SearchApiSort::query in Search API 8

Called to add the sort to a query.

Overrides SortPluginBase::query

File

src/Plugin/views/sort/SearchApiSort.php, line 24

Class

SearchApiSort
Provides a sort plugin for Search API views.

Namespace

Drupal\search_api\Plugin\views\sort

Code

public function query() {

  // When there are exposed sorts, the "exposed form" plugin will set
  // $query->orderby to an empty array. Therefore, if that property is set,
  // we here remove all previous sorts.
  // @todo Is this still true in D8?
  // @todo Check whether #2145547 is still a problem here.
  if (isset($this->query->orderby)) {
    unset($this->query->orderby);
    $sort =& $this->query
      ->getSort();
    $sort = [];
  }
  $this->query
    ->sort($this->realField, $this->options['order']);
}