You are here

public static function Utility::formatHighlighting in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::formatHighlighting()
  2. 8.2 src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::formatHighlighting()
  3. 4.x src/Utility/Utility.php \Drupal\search_api_solr\Utility\Utility::formatHighlighting()

Changes highlighting tags from our custom, HTML-safe ones to HTML.

Parameters

string|array $snippet: The snippet(s) to format.

string|array $prefix: (optional) The opening tag to replace "[HIGHLIGHT]". Defaults to "<strong>".

string|array $suffix: (optional) The closing tag to replace "[/HIGHLIGHT]". Defaults to "</strong>".

Return value

string|array The snippet(s), properly formatted as HTML.

1 call to Utility::formatHighlighting()
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 232

Class

Utility
Provides various helper functions for Solr backends.

Namespace

Drupal\search_api_solr\Utility

Code

public static function formatHighlighting($snippet, $prefix = '<strong>', $suffix = '</strong>') {
  return str_replace([
    '[HIGHLIGHT]',
    '[/HIGHLIGHT]',
  ], [
    $prefix,
    $suffix,
  ], $snippet);
}