You are here

class Score in Drupal 10

Same name in this branch
  1. 10 core/modules/search/src/Plugin/views/sort/Score.php \Drupal\search\Plugin\views\sort\Score
  2. 10 core/modules/search/src/Plugin/views/field/Score.php \Drupal\search\Plugin\views\field\Score
Same name and namespace in other branches
  1. 8 core/modules/search/src/Plugin/views/sort/Score.php \Drupal\search\Plugin\views\sort\Score
  2. 9 core/modules/search/src/Plugin/views/sort/Score.php \Drupal\search\Plugin\views\sort\Score

Sort handler for sorting by search score.

Plugin annotation

@ViewsSort("search_score");

Hierarchy

Expanded class hierarchy of Score

Related topics

1 string reference to 'Score'
NodeViewsData::getViewsData in core/modules/node/src/NodeViewsData.php

File

core/modules/search/src/Plugin/views/sort/Score.php, line 14

Namespace

Drupal\search\Plugin\views\sort
View source
class Score extends SortPluginBase {

  /**
   * {@inheritdoc}
   */
  public function query() {

    // Check to see if the search filter/argument added 'score' to the table.
    // Our filter stores it as $handler->search_score -- and we also
    // need to check its relationship to make sure that we're using the same
    // one or obviously this won't work.
    foreach ([
      'filter',
      'argument',
    ] as $type) {
      foreach ($this->view->{$type} as $handler) {
        if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
          $this->query
            ->addOrderBy(NULL, NULL, $this->options['order'], $handler->search_score);
          $this->tableAlias = $handler->tableAlias;
          return;
        }
      }
    }

    // Do nothing if there is no filter/argument in place. There is no way
    // to sort on scores.
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Score::query public function Called to add the sort to a query. Overrides SortPluginBase::query
SortPluginBase::adminSummary public function Display whether or not the sort order is ascending or descending.
SortPluginBase::buildExposeForm public function
SortPluginBase::buildOptionsForm public function Basic options for all sort criteria. 2
SortPluginBase::canExpose public function Determine if a sort can be exposed.
SortPluginBase::defaultExposeOptions public function Provide default options for exposed sorts.
SortPluginBase::defineOptions protected function 1
SortPluginBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
SortPluginBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
SortPluginBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
SortPluginBase::showExposeButton public function Shortcut to display the expose/hide button.
SortPluginBase::showSortForm protected function Shortcut to display the value form.
SortPluginBase::sortOptions protected function Provide a list of options for the default sort form.
SortPluginBase::sortSubmit public function
SortPluginBase::sortValidate protected function
SortPluginBase::submitOptionsForm public function Simple submit handler.
SortPluginBase::trustedCallbacks public static function
SortPluginBase::validateExposeForm public function Validate the options form.
SortPluginBase::validateOptionsForm public function Simple validate handler.