You are here

public static function Utility::getHighlightedKeys in Search API Solr 8.2

Same name and namespace in other branches
  1. 8.3 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::getHighlightedKeys()
  2. 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.

1 call to Utility::getHighlightedKeys()
SearchApiSolrBackend::getHighlighting in src/Plugin/search_api/backend/SearchApiSolrBackend.php
Extract and format highlighting information for a specific item.

File

src/Utility/Utility.php, line 205

Class

Utility
Provides various helper functions for Solr backends.

Namespace

Drupal\search_api_solr\Utility

Code

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 = array_merge($keys, $matches[1]);
    }
  }
  return array_unique($keys);
}