Last active
August 8, 2021 12:37
-
-
Save GroupDocsGists/4fab169c40c4a8d27581d156002daea3 to your computer and use it in GitHub Desktop.
Search and highlight text in all the documents of folder using Java
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 the full text search results of multiple documents in a folder in Java | |
Index index = new Index("path/indexingFolder"); | |
index.add("path/documentsFolderPath"); // Synchronous indexing documents from the specified folder | |
String query = "draw"; // Specify a search query | |
SearchResult result = index.search(query); // Searching in the index | |
for (int i = 0; i < result.getDocumentCount(); i++) | |
{ | |
FoundDocument document = result.getFoundDocument(i); | |
String path = "path/Highlighted-"+ i +".html"; | |
OutputAdapter outputAdapter = new FileOutputAdapter(path); | |
HtmlHighlighter highlighter = new HtmlHighlighter(outputAdapter); // Creating the highlighter | |
index.highlight(document, highlighter); // Generates HTML formatted output document with highlighted 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
// Search specified text in multiple PDF, Word, Excel, HTML documents with in a folder using Java | |
Index index = new Index("path/indexingFolder"); | |
index.add("path/documentsFolderPath"); | |
// Searching in index for specified text | |
SearchResult result = index.search("Draw"); | |
for (int i = 0; i < result.getDocumentCount(); i++) { | |
FoundDocument document = result.getFoundDocument(i); | |
System.out.println("Document Path: " + document.getDocumentInfo().getFilePath()); | |
System.out.println("Occurrence : " + document.getOccurrenceCount()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment