Created
October 10, 2019 12:39
-
-
Save GroupDocsGists/297af296115ebb29b5a8ded0b6ec9cac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string indexFolder = @"c:\MyIndex"; | |
string documentFolder = @"c:\MyDocuments"; | |
// Creating index | |
Index index = new Index(indexFolder); | |
// Adding documents to index | |
index.Add(documentFolder); | |
// Searching | |
SearchResult result = index.Search("hobbit"); | |
// Highlighting found terms in short HTML snippets | |
if (result.DocumentCount > 0) | |
{ | |
FoundDocument document = result.GetFoundDocument(0); | |
HtmlFragmentHighlighter highlighter = new HtmlFragmentHighlighter(); | |
index.Highlight(document, highlighter); | |
// 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(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment