NodeSearch.php in Multiversion 8        
                          
                  
                        
  
  
  
  
  
File
  src/Entity/Search/NodeSearch.php
  
    View source  
  <?php
namespace Drupal\multiversion\Entity\Search;
use Drupal\Core\Database\Query\Condition;
use Drupal\Search\SearchQuery;
use Drupal\node\Plugin\Search\NodeSearch as CoreNodeSearch;
class NodeSearch extends CoreNodeSearch {
  
  protected function findResults() {
    $keys = $this->keywords;
    
    $query = $this->database
      ->select('search_index', 'i', [
      'target' => 'replica',
    ])
      ->extend('Drupal\\search\\SearchQuery')
      ->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
    $query
      ->join('node_field_data', 'n', 'n.nid = i.sid AND n.langcode = i.langcode AND _deleted = 0');
    $query
      ->condition('n.status', 1)
      ->addTag('node_access')
      ->searchExpression($keys, $this
      ->getPluginId());
    
    $parameters = $this
      ->getParameters();
    if (!empty($parameters['f']) && is_array($parameters['f'])) {
      $filters = [];
      
      $pattern = '/^(' . implode('|', array_keys($this->advanced)) . '):([^ ]*)/i';
      foreach ($parameters['f'] as $item) {
        if (preg_match($pattern, $item, $m)) {
          
          $filters[$m[1]][$m[2]] = $m[2];
        }
      }
      
      foreach ($filters as $option => $matched) {
        $info = $this->advanced[$option];
        
        $operator = empty($info['operator']) ? 'OR' : $info['operator'];
        $where = new Condition($operator);
        foreach ($matched as $value) {
          $where
            ->condition($info['column'], $value);
        }
        $query
          ->condition($where);
        if (!empty($info['join'])) {
          $query
            ->join($info['join']['table'], $info['join']['alias'], $info['join']['condition']);
        }
      }
    }
    
    $this
      ->addNodeRankings($query);
    
    $find = $query
      ->fields('i', [
      'langcode',
    ])
      ->groupBy('i.langcode')
      ->limit(10)
      ->execute();
    
    $status = $query
      ->getStatus();
    if ($status & SearchQuery::EXPRESSIONS_IGNORED) {
      $this->messenger
        ->addWarning($this
        ->t('Your search used too many AND/OR expressions. Only the first @count terms were included in this search.', [
        '@count' => $this->searchSettings
          ->get('and_or_limit'),
      ]));
    }
    if ($status & SearchQuery::LOWER_CASE_OR) {
      $this->messenger
        ->addWarning($this
        ->t('Search for either of the two terms with uppercase <strong>OR</strong>. For example, <strong>cats OR dogs</strong>.'));
    }
    if ($status & SearchQuery::NO_POSITIVE_KEYWORDS) {
      $this->messenger
        ->addWarning($this
        ->formatPlural($this->searchSettings
        ->get('index.minimum_word_size'), 'You must include at least one keyword to match in the content, and punctuation is ignored.', 'You must include at least one keyword to match in the content. Keywords must be at least @count characters, and punctuation is ignored.'));
    }
    return $find;
  }
}
 
Classes
        
  
  
      
      
         
      
                  
            Name            | 
                  
            Description           | 
              
    
    
          
                  | 
            NodeSearch           | 
                  
            Handles searching for node entities using the Search module index.           |