protected function SearchApiDbService::splitKeys in Search API Database Search 7
Splits a keyword expression into separate words.
Used as a helper method in prepareKeys().
Parameters
array|string|null $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.
2 calls to SearchApiDbService::splitKeys()
- SearchApiDbService::getAutocompleteSuggestions in ./
service.inc - Implements SearchApiAutocompleteInterface::getAutocompleteSuggestions().
- SearchApiDbService::prepareKeys in ./
service.inc - Removes nested expressions and phrase groupings from the search keys.
File
- ./
service.inc, line 1407 - Contains SearchApiDbService.
Class
- SearchApiDbService
- Indexes and searches items using the database.
Code
protected function splitKeys($keys, $tokenizer_active = FALSE) {
if (is_scalar($keys)) {
$proc = drupal_strtolower(trim($keys));
if (is_numeric($proc)) {
return ltrim($proc, '-0');
}
elseif (drupal_strlen($proc) < $this->options['min_chars']) {
$this->ignored[$keys] = 1;
return NULL;
}
if ($tokenizer_active) {
$words = array_filter(explode(' ', $proc), 'strlen');
}
else {
$words = preg_split('/[^\\p{L}\\p{N}]+/u', $proc, -1, PREG_SPLIT_NO_EMPTY);
}
if (count($words) > 1) {
$proc = $this
->splitKeys($words, $tokenizer_active);
if ($proc) {
$proc['#conjunction'] = 'AND';
}
else {
$proc = NULL;
}
}
return $proc;
}
foreach ($keys as $i => $key) {
if (element_child($i)) {
$keys[$i] = $this
->splitKeys($key, $tokenizer_active);
}
}
return array_filter($keys);
}