Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. SearchQuery.php

function 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 360

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,
    ];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal