Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.