You are here

public function FilesExtractor::limitBytes in Search API attachments 8

Same name and namespace in other branches
  1. 9.0.x src/Plugin/search_api/processor/FilesExtractor.php \Drupal\search_api_attachments\Plugin\search_api\processor\FilesExtractor::limitBytes()

Limit the indexed text to first N bytes.

Parameters

string $extracted_text: The hole extracted text.

Return value

string The first N bytes of the extracted text that will be indexed and cached.

1 call to FilesExtractor::limitBytes()
FilesExtractor::extractOrGetFromCache in src/Plugin/search_api/processor/FilesExtractor.php
Extract non text file data or get it from cache if available and cache it.

File

src/Plugin/search_api/processor/FilesExtractor.php, line 399

Class

FilesExtractor
Provides file fields processor.

Namespace

Drupal\search_api_attachments\Plugin\search_api\processor

Code

public function limitBytes($extracted_text) {

  // Default the configuration to a sensible amount of text to extract and
  // cache in the database. 1 million characters should be enough for most
  // cases.
  $bytes = Bytes::toInt('1 MB');
  if (isset($this->configuration['number_first_bytes'])) {
    $bytes = Bytes::toInt($this->configuration['number_first_bytes']);
  }

  // If $bytes is 0 return all items.
  if ($bytes == 0) {
    return $extracted_text;
  }
  else {
    $extracted_text = mb_strcut($extracted_text, 0, $bytes);
  }
  return $extracted_text;
}