3 namespace Drupal\search\Plugin\views\sort;
5 use Drupal\views\Plugin\views\sort\SortPluginBase;
8 * Sort handler for sorting by search score.
10 * @ingroup views_sort_handlers
12 * @ViewsSort("search_score")
14 class Score extends SortPluginBase {
19 public function query() {
20 // Check to see if the search filter/argument added 'score' to the table.
21 // Our filter stores it as $handler->search_score -- and we also
22 // need to check its relationship to make sure that we're using the same
23 // one or obviously this won't work.
24 foreach (['filter', 'argument'] as $type) {
25 foreach ($this->view->{$type} as $handler) {
26 if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
27 $this->query->addOrderBy(NULL, NULL, $this->options['order'], $handler->search_score);
28 $this->tableAlias = $handler->tableAlias;
34 // Do nothing if there is no filter/argument in place. There is no way