public static function Utility::getHighlightedKeys in Search API Solr 8.3
Same name and namespace in other branches
- 8.2 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getHighlightedKeys()
- 4.x src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getHighlightedKeys()
Returns the highlighted keys from a snippet highlighted by Solr.
Parameters
string|array $snippets: The snippet(s) to format.
Return value
array The highlighted keys.
2 calls to Utility::getHighlightedKeys()
- SearchApiSolrBackend::getHighlighting in src/
Plugin/ search_api/ backend/ SearchApiSolrBackend.php - Extract and format highlighting information for a specific item.
- UtilitiesTest::testHighlightedKeys in tests/
src/ Kernel/ UtilitiesTest.php - Tests extracting of highlighted keys.
File
- src/
Utility/ Utility.php, line 201
Class
- Utility
- Provides various helper functions for Solr backends.
Namespace
Drupal\search_api_solr\UtilityCode
public static function getHighlightedKeys($snippets) {
if (is_string($snippets)) {
$snippets = [
$snippets,
];
}
$keys = [
[],
];
foreach ($snippets as $snippet) {
if (preg_match_all('@\\[HIGHLIGHT\\](.+?)\\[/HIGHLIGHT\\]@', $snippet, $matches)) {
$keys[] = $matches[1];
}
}
return array_unique(array_merge(...$keys));
}