Same name and namespace in other branches
  1. 8.9.x core/modules/search/src/SearchQuery.php \Drupal\search\SearchQuery::parseWord()
  2. 9 core/modules/search/src/SearchQuery.php \Drupal\search\SearchQuery::parseWord()

Parses a word or phrase for parseQuery().

Splits a phrase into words. Adds its words to $this->words, if it is not already there. Returns a list containing the number of new words found, and the total number of words in the phrase.

1 call to SearchQuery::parseWord()
SearchQuery::parseSearchExpression in core/modules/search/src/SearchQuery.php
Parses the search query into SQL conditions.

File

core/modules/search/src/SearchQuery.php, line 359

Class

SearchQuery
Search query extender and helper functions.

Namespace

Drupal\search

Code

protected function parseWord($word) {
  $num_new_scores = 0;
  $num_valid_words = 0;

  // Determine the scorewords of this word/phrase.
  $split = explode(' ', $word);
  foreach ($split as $s) {
    $num = is_numeric($s);
    if ($num || mb_strlen($s) >= \Drupal::config('search.settings')
      ->get('index.minimum_word_size')) {
      if (!isset($this->words[$s])) {
        $this->words[$s] = $s;
        $num_new_scores++;
      }
      $num_valid_words++;
    }
  }

  // Return matching snippet and number of added words.
  return [
    $num_new_scores,
    $num_valid_words,
  ];
}