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