Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created October 10, 2019 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/297af296115ebb29b5a8ded0b6ec9cac to your computer and use it in GitHub Desktop.
Save GroupDocsGists/297af296115ebb29b5a8ded0b6ec9cac to your computer and use it in GitHub Desktop.
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