public function SolrExtractor::extract in Search API attachments 8
Same name and namespace in other branches
- 9.0.x src/Plugin/search_api_attachments/SolrExtractor.php \Drupal\search_api_attachments\Plugin\search_api_attachments\SolrExtractor::extract()
Extract file with a search api solr backend.
Parameters
\Drupal\file\Entity\File $file: A file object.
Return value
string The text extracted from the file.
Overrides TextExtractorPluginBase::extract
File
- src/
Plugin/ search_api_attachments/ SolrExtractor.php, line 61
Class
- SolrExtractor
- Provides solr extractor.
Namespace
Drupal\search_api_attachments\Plugin\search_api_attachmentsCode
public function extract(File $file) {
$filepath = $this
->getRealpath($file
->getFileUri());
// Load the chosen Solr server entity.
$conditions = [
'status' => TRUE,
'id' => $this->configuration['solr_server'],
];
$server = $this->entityTypeManager
->getStorage('search_api_server')
->loadByProperties($conditions);
$server = reset($server);
// Get the Solr backend.
/** @var \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend $backend */
$backend = $server
->getBackend();
if (!$backend
->isAvailable()) {
throw new \Exception('Solr Exctractor is not available.');
}
// Extract the content.
$xml_data = $backend
->extractContentFromFile($filepath);
return self::extractBody($xml_data);
}