Highlight

Highlight(FoundDocument, Highlighter)

Generates HTML formatted text with highlighted found terms.

public void Highlight(FoundDocument document, Highlighter highlighter)
Parameter Type Description
document FoundDocument The found document.
highlighter Highlighter The search result highlighter.

Examples

The example demonstrates how to highlight occurrences in HTML formatted text.

string indexFolder = @"c:\MyIndex\";
string documentFolder = @"c:\MyDocuments\";

// Creating an index
Index index = new Index(indexFolder);

// Indexing documents from the specified folder
index.Add(documentFolder);

// Search for the word 'eternity'
SearchResult result = index.Search("eternity");

// Highlighting occurrences in text
if (result.DocumentCount > 0)
{
    FoundDocument document = result.GetFoundDocument(0); // Getting the first found document
    OutputAdapter outputAdapter = new FileOutputAdapter(@"c:\Highlighted.html"); // Creating an output adapter to the file
    Highlighter highlighter = new HtmlHighlighter(outputAdapter); // Creating the highlighter object
    index.Highlight(document, highlighter); // Generating HTML formatted text with highlighted occurrences
}

See Also


Highlight(FoundDocument, Highlighter, HighlightOptions)

Generates HTML formatted text with highlighted found terms.

public void Highlight(FoundDocument document, Highlighter highlighter, HighlightOptions options)
Parameter Type Description
document FoundDocument The found document.
highlighter Highlighter The search result highlighter.
options HighlightOptions The highlight options.

Examples

The example demonstrates how to highlight occurrences in HTML formatted text.

string indexFolder = @"c:\MyIndex\";
string documentFolder = @"c:\MyDocuments\";

// Creating an index
Index index = new Index(indexFolder);

// Indexing documents from the specified folder
index.Add(documentFolder);

// Search for the word 'eternity'
SearchResult result = index.Search("eternity");

// Highlighting occurrences in text
if (result.DocumentCount > 0)
{
    FoundDocument document = result.GetFoundDocument(0); // Getting the first found document
    OutputAdapter outputAdapter = new FileOutputAdapter(@"c:\Highlighted.html"); // Creating an output adapter to the file
    Highlighter highlighter = new HtmlHighlighter(outputAdapter); // Creating the highlighter object
    HighlightOptions options = new HighlightOptions(); // Creating the highlight options object
    options.TermsBefore = 5;
    options.TermsAfter = 5;
    options.TermsTotal = 15;
    index.Highlight(document, highlighter, options); // Generating HTML formatted text with highlighted occurrences
}

See Also