AbstractTextExtractor
abstract class \
- Implements
- StructuredTextExtractorInterface, TextExtractorInterface, LoggerAwareInterface
- Uses
- LoggerAwareTrait
Base class for the text extractors of indexed_search, working on a local copy of the resource and, depending on the file type, on external tools.
The extractors work on any system resource. They also implement the file-based TextExtractorInterface, so they serve consumers of TextExtractorRegistry::getTextExtractor() as well.
Internal
Table of Contents
Interfaces
- StructuredTextExtractorInterface
- A text extractor that is bound to MIME types and returns, next to the text, the metadata it found in the resource, such as a title or keywords.
- TextExtractorInterface
- Interface for text extractors, which are registered as tagged services via the #[AsTextExtractor] attribute or the 'fal.text_extractor' service tag.
- LoggerAwareInterface
Properties
Methods
- __construct() : mixed
- canExtractText() : bool
- Checks if the given file can be read by this extractor
- extractStructuredText() : ExtractedText
- The actual text extraction, returning the text and the metadata of the resource
- extractText() : string
- The actual text extraction, returning a string of the file's content
- getSupportedMimeTypes() : array<int, string>
- Lowercase MIME types which this extractor can currently handle. Generic detections, such as "application/zip" for a Word document, are resolved to the concrete MIME type by the file extension via $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['mimeTypeCompatibility'], so an extractor does not need to declare them.
- removeEndJunk() : string
- Removes some strange char(12) characters and line breaks that tend to occur at the end of external tool output.
- checkRequiredTools() : bool
- extractFromLocalFile() : ExtractedText
- getMimeTypes() : array<int, string>
- getMissingTools() : array<int, string>
- getRequiredTools() : array<int, "pdfinfo"|"pdftotext"|"catdoc"|"ppthtml"|"xlhtml"|"unzip"|"unrtf">
- getToolPath() : string
- joinOutput() : string
- stripXmlTags() : string
- withLocalFile() : T
- Provides a local copy of the file to the callback, and cleans up afterwards.
Properties
$commandExecutor read-only
protected
ExternalCommandExecutor
$commandExecutor
$toolConfiguration read-only
protected
ExternalToolConfiguration
$toolConfiguration
Methods
__construct()
public
__construct(ExternalToolConfiguration $toolConfiguration, ExternalCommandExecutor $commandExecutor) : mixed
Parameters
- $toolConfiguration : ExternalToolConfiguration
- $commandExecutor : ExternalCommandExecutor
canExtractText()
Checks if the given file can be read by this extractor
public
canExtractText(FileInterface $file) : bool
Parameters
- $file : FileInterface
Return values
boolextractStructuredText()
The actual text extraction, returning the text and the metadata of the resource
public
extractStructuredText(SystemResourceInterface $file) : ExtractedText
Parameters
- $file : SystemResourceInterface
Return values
ExtractedTextextractText()
The actual text extraction, returning a string of the file's content
public
extractText(FileInterface $file) : string
Parameters
- $file : FileInterface
Return values
stringgetSupportedMimeTypes()
Lowercase MIME types which this extractor can currently handle. Generic detections, such as "application/zip" for a Word document, are resolved to the concrete MIME type by the file extension via $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['mimeTypeCompatibility'], so an extractor does not need to declare them.
public
getSupportedMimeTypes() : array<int, string>
Return values
array<int, string>removeEndJunk()
Removes some strange char(12) characters and line breaks that tend to occur at the end of external tool output.
public
static removeEndJunk(string $string) : string
Parameters
- $string : string
Return values
stringcheckRequiredTools()
protected
checkRequiredTools(SystemResourceInterface $file) : bool
Parameters
- $file : SystemResourceInterface
Return values
boolextractFromLocalFile()
protected
abstract extractFromLocalFile(SystemResourceInterface $file, string $localFilePath) : ExtractedText
Parameters
- $file : SystemResourceInterface
- $localFilePath : string
Return values
ExtractedTextgetMimeTypes()
protected
abstract getMimeTypes() : array<int, string>
Return values
array<int, string>getMissingTools()
protected
getMissingTools() : array<int, string>
Return values
array<int, string>getRequiredTools()
protected
getRequiredTools() : array<int, "pdfinfo"|"pdftotext"|"catdoc"|"ppthtml"|"xlhtml"|"unzip"|"unrtf">
Return values
array<int, "pdfinfo"|"pdftotext"|"catdoc"|"ppthtml"|"xlhtml"|"unzip"|"unrtf">getToolPath()
protected
getToolPath(string $tool) : string
Parameters
- $tool : string
Return values
stringjoinOutput()
protected
joinOutput(array<int, string> $output) : string
Parameters
- $output : array<int, string>
Return values
stringstripXmlTags()
protected
stripXmlTags(string $xml) : string
Parameters
- $xml : string
Return values
stringwithLocalFile()
Provides a local copy of the file to the callback, and cleans up afterwards.
protected
withLocalFile(SystemResourceInterface $file, callable(string): T $callback) : T
Parameters
- $file : SystemResourceInterface
- $callback : callable(string): T