IFieldExtractor class

IFieldExtractor class

Provides methods for extracting fields from a document.

Learn more:

The IFieldExtractor type exposes the following members:

Methods

Method Description
get_fields Extracts all fields from the specified document.
get_fields Extracts all fields from the specified document.

Properties

Property Description
extensions The supported extensions.

Example

from groupdocs.search import Index, IndexSettings
from groupdocs.search.common import DocumentField


# A custom extractor: the extensions it handles, and the fields it extracts
class LogExtractor(object):
    extensions = [".log"]

    def get_fields(self, source):
        # source is a file path, or a binary stream for a document added from a stream
        if isinstance(source, str):
            with open(source, encoding="utf-8-sig") as f:
                text = f.read()
        else:
            text = source.read().decode("utf-8-sig")
        return [DocumentField("Content", text)]


# Using the custom extractor for indexing
settings = IndexSettings()
settings.custom_extractors.add(LogExtractor())
index = Index("./MyIndex", settings)  # Create or load an index
index.add("./documents")  # Index documents

See Also