Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / search / src / Plugin / views / sort / Score.php
1 <?php
2
3 namespace Drupal\search\Plugin\views\sort;
4
5 use Drupal\views\Plugin\views\sort\SortPluginBase;
6
7 /**
8  * Sort handler for sorting by search score.
9  *
10  * @ingroup views_sort_handlers
11  *
12  * @ViewsSort("search_score")
13  */
14 class Score extends SortPluginBase {
15
16   /**
17    * {@inheritdoc}
18    */
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;
29           return;
30         }
31       }
32     }
33
34     // Do nothing if there is no filter/argument in place. There is no way
35     // to sort on scores.
36   }
37
38 }