You are here

protected function Database::splitKeys in Search API 8

Splits a keyword expression into separate words.

Used as a helper method in prepareKeys().

Parameters

array|string $keys: The keys to split.

bool $tokenizer_active: (optional) TRUE if we can rely on the "Tokenizer" processor already having preprocessed the keywords.

Return value

array|string|null The keys split into separate words.

1 call to Database::splitKeys()
Database::prepareKeys in modules/search_api_db/src/Plugin/search_api/backend/Database.php
Removes nested expressions and phrase groupings from the search keys.

File

modules/search_api_db/src/Plugin/search_api/backend/Database.php, line 1872

Class

Database
Indexes and searches items using the database.

Namespace

Drupal\search_api_db\Plugin\search_api\backend

Code

protected function splitKeys($keys, bool $tokenizer_active = FALSE) {
  if (is_scalar($keys)) {
    $processed_keys = $this->dbmsCompatibility
      ->preprocessIndexValue(trim($keys));
    if (is_numeric($processed_keys)) {
      return ltrim($processed_keys, '-0');
    }
    elseif (mb_strlen($processed_keys) < $this->configuration['min_chars']) {
      $this->ignored[$keys] = 1;
      return NULL;
    }
    if ($tokenizer_active) {
      $words = array_filter(explode(' ', $processed_keys), 'strlen');
    }
    else {
      $words = static::splitIntoWords($processed_keys);
    }
    if (count($words) > 1) {
      $processed_keys = $this
        ->splitKeys($words, $tokenizer_active);
      if ($processed_keys) {
        $processed_keys['#conjunction'] = 'AND';
      }
      else {
        $processed_keys = NULL;
      }
    }
    return $processed_keys;
  }
  foreach ($keys as $i => $key) {
    if (Element::child($i)) {
      $keys[$i] = $this
        ->splitKeys($key, $tokenizer_active);
    }
  }
  return array_filter($keys);
}