HtmlFragmentHighlighter Class |
Namespace: GroupDocs.Search.Highlighters
The HtmlFragmentHighlighter type exposes the following members.
Name | Description | |
---|---|---|
![]() | HtmlFragmentHighlighter |
Initializes a new instance of the HtmlFragmentHighlighter class.
|
Name | Description | |
---|---|---|
![]() | Equals | (Inherited from Object.) |
![]() | Finalize | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetResult |
Gets an array of resulting fragment containers.
|
![]() | GetType | (Inherited from Object.) |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | ToString | (Inherited from Object.) |
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(); } } }