Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created December 10, 2023 15:06
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/48331f68992c12572c76fe277ded0348 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/48331f68992c12572c76fe277ded0348 to your computer and use it in GitHub Desktop.
Print Search Results
// Highlight and Print Search Results for all the documents
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