highlight method

highlight

Generates HTML formatted text with highlighted found terms.

def highlight(self, document, highlighter):
    ...
Parameter Type Description
document FoundDocument The found document.
highlighter Highlighter The search result highlighter.

Example

import os
from groupdocs.search import Index
from groupdocs.search.common import FileOutputAdapter
from groupdocs.search.highlighters import DocumentHighlighter
from groupdocs.search.options import OutputFormat

os.makedirs("./output", exist_ok=True)

with Index("./index") as index:
    index.add("./documents")
    result = index.search("Einstein")
    if result.document_count > 0:
        adapter = FileOutputAdapter(OutputFormat.HTML, "./output/Highlighted.html")
        highlighter = DocumentHighlighter(adapter)
        index.highlight(result.get_found_document(0), highlighter)
        print("Written: ./output/Highlighted.html")

highlight

Generates HTML formatted text with highlighted found terms.

def highlight(self, document, highlighter, options):
    ...
Parameter Type Description
document FoundDocument The found document.
highlighter Highlighter The search result highlighter.
options HighlightOptions The highlight options.

Example

from groupdocs.search import Index
from groupdocs.search.common import FileOutputAdapter
from groupdocs.search.highlighters import DocumentHighlighter
from groupdocs.search.options import OutputFormat, HighlightOptions

with Index("./index") as index:
    result = index.search("Einstein")
    if result.document_count > 0:
        adapter = FileOutputAdapter(OutputFormat.HTML, "./output/Highlighted.html")
        highlighter = DocumentHighlighter(adapter)
        options = HighlightOptions()
        options.terms_before = 5
        options.terms_after = 5
        options.terms_total = 15
        index.highlight(result.get_found_document(0), highlighter, options)

Aliases

These names call highlight too, limited to the overloads listed.

Alias Accepts
highlight_found_document highlight_found_document(document, highlighter, options)
highlight_found_document(document, highlighter)

See Also