protected function Highlight::getKeywords in Search API 8
Extracts the positive keywords used in a search query.
Parameters
\Drupal\search_api\Query\QueryInterface $query: The query from which to extract the keywords.
Return value
string[] An array of all unique positive keywords used in the query.
1 call to Highlight::getKeywords()
- Highlight::postprocessSearchResults in src/
Plugin/ search_api/ processor/ Highlight.php - Postprocess search results before they are returned by the query.
File
- src/
Plugin/ search_api/ processor/ Highlight.php, line 386
Class
- Highlight
- Adds a highlighted excerpt to results and highlights returned fields.
Namespace
Drupal\search_api\Plugin\search_api\processorCode
protected function getKeywords(QueryInterface $query) {
$keys = $query
->getOriginalKeys();
if (!$keys) {
return [];
}
if (is_array($keys)) {
return $this
->flattenKeysArray($keys);
}
$keywords_in = preg_split(static::$split, $keys);
if (!$keywords_in) {
return [];
}
// Assure there are no duplicates. (This is actually faster than
// array_unique() by a factor of 3 to 4.)
// Remove quotes from keywords.
$keywords = [];
foreach (array_filter($keywords_in) as $keyword) {
if ($keyword = trim($keyword, "'\"")) {
$keywords[$keyword] = $keyword;
}
}
return $keywords;
}