You are here

protected function NodeSearch::addNodeRankings in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/node/src/Plugin/Search/NodeSearch.php \Drupal\node\Plugin\Search\NodeSearch::addNodeRankings()

Adds the configured rankings to the search query.

Parameters

$query: A query object that has been extended with the Search DB Extender.

1 call to NodeSearch::addNodeRankings()
NodeSearch::findResults in core/modules/node/src/Plugin/Search/NodeSearch.php
Queries to find search results, and sets status messages.

File

core/modules/node/src/Plugin/Search/NodeSearch.php, line 450

Class

NodeSearch
Handles searching for node entities using the Search module index.

Namespace

Drupal\node\Plugin\Search

Code

protected function addNodeRankings(SelectExtender $query) {
  if ($ranking = $this
    ->getRankings()) {
    $tables =& $query
      ->getTables();
    foreach ($ranking as $rank => $values) {
      if (isset($this->configuration['rankings'][$rank]) && !empty($this->configuration['rankings'][$rank])) {
        $node_rank = $this->configuration['rankings'][$rank];

        // If the table defined in the ranking isn't already joined, then add it.
        if (isset($values['join']) && !isset($tables[$values['join']['alias']])) {
          $query
            ->addJoin($values['join']['type'], $values['join']['table'], $values['join']['alias'], $values['join']['on']);
        }
        $arguments = isset($values['arguments']) ? $values['arguments'] : [];
        $query
          ->addScore($values['score'], $arguments, $node_rank);
      }
    }
  }
}