Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active December 10, 2023 15:07
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/dbaeb3528aed71d3f9fa02618e86d6c0 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/dbaeb3528aed71d3f9fa02618e86d6c0 to your computer and use it in GitHub Desktop.
Print Search Results
// Highlight and Print Search Results for all the documents using C#
for (int i = 0; i < result.DocumentCount; i++)
{
FoundDocument document = result.GetFoundDocument(i);
OutputAdapter outputAdapter = new FileOutputAdapter(OutputFormat.Html, indexFolder + "/Highlight" + i + ".html");
Highlighter highlighter = new DocumentHighlighter(outputAdapter);
index.Highlight(document, highlighter);
Console.WriteLine("\tDocument: " + document.DocumentInfo.FilePath);
Console.WriteLine("\tOccurrences: " + document.OccurrenceCount);
for (int j = 0; j < document.FoundFields.Length; j++)
{
FoundDocumentField field = document.FoundFields[j];
Console.WriteLine("\t\tField: " + field.FieldName);
Console.WriteLine("\t\tOccurrences: " + document.OccurrenceCount);
// Printing found terms
if (field.Terms != null)
{
for (int k = 0; k < field.Terms.Length; k++)
{
Console.WriteLine("\t\t\t" + field.Terms[k].PadRight(20) + field.TermsOccurrences[k]);
}
}
}
Console.WriteLine("===========================================");
}
// Highlight and Print Search Results for all the documents using Java
for (int i = 0 ; i < result.getDocumentCount(); i++)
{
FoundDocument document = result.getFoundDocument(i);
OutputAdapter outputAdapter = new FileOutputAdapter(OutputFormat.Html, "path/Highlight" + i + ".html");
Highlighter highlighter = new DocumentHighlighter(outputAdapter);
index.highlight(document, highlighter);
System.out.println("\tDocument: " + document.getDocumentInfo().getFilePath());
System.out.println("\tOccurrences: " + document.getOccurrenceCount());
for (FoundDocumentField field : document.getFoundFields()) {
System.out.println("\t\tField: " + field.getFieldName());
System.out.println("\t\tOccurrences: " + field.getOccurrenceCount());
// Printing found terms
if (field.getTerms() != null) {
for (int k = 0; k < field.getTerms().length; k++) {
System.out.println("\t\t\t" + field.getTerms()[k] + " - " + field.getTermsOccurrences()[k]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment