HtmlFragmentHighlighter Class
Represents a search result highlighter that highlights search results in HTML formatted text fragments.
Inheritance Hierarchy

Namespace: GroupDocs.Search.Highlighters
Assembly: GroupDocs.Search (in GroupDocs.Search.dll) Version: 20.8
Syntax
public class HtmlFragmentHighlighter : Highlighter

The HtmlFragmentHighlighter type exposes the following members.

Constructors
  NameDescription
Public methodHtmlFragmentHighlighter
Initializes a new instance of the HtmlFragmentHighlighter class.
Methods
  NameDescription
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetResult
Gets an array of resulting fragment containers.
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodToString (Inherited from Object.)
Remarks
Examples
The example demonstrates a typical usage of the class.
C#
string indexFolder = @"c:\MyIndex\";
string documentsFolder = @"c:\MyDocuments\";

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

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

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

// Assigning highlight options
HighlightOptions options = new HighlightOptions();
options.TermsBefore = 5;
options.TermsAfter = 5;
options.TermsTotal = 15;

// Highlighting found words in the text of a document
FoundDocument document = result.GetFoundDocument(0);
HtmlFragmentHighlighter highlighter = new HtmlFragmentHighlighter();
index.Highlight(document, highlighter, options);

// Getting the result
FragmentContainer[] fragmentContainers = highlighter.GetResult();
for (int i = 0; i < fragmentContainers.Length; i++)
{
    FragmentContainer container = fragmentContainers[i];
    string[] fragments = container.GetFragments();
    if (fragments.Length > 0)
    {
        Console.WriteLine(container.FieldName);
        Console.WriteLine();
        for (int j = 0; j < fragments.Length; j++)
        {
            // Printing HTML markup to console
            Console.WriteLine(fragments[j]);
            Console.WriteLine();
        }
    }
}
See Also