public class FragmentHighlighter extends Highlighter implements IFragmentHighlighter
Learn more
String indexFolder = "c:\\MyIndex\\";
String documentsFolder = "c:\\MyDocuments\\";
// Creating an index
Index index = new Index(indexFolder);
// Indexing documents from the specified folder
index.add(documentsFolder);
// Search for the word 'Einstein'
SearchResult result = index.search("Einstein");
// Assigning highlight options
HighlightOptions options = new HighlightOptions();
options.setTermsBefore(5);
options.setTermsAfter(5);
options.setTermsTotal(15);
// Highlighting found words in the text of a document
FoundDocument document = result.getFoundDocument(0);
FragmentHighlighter highlighter = new FragmentHighlighter(OutputFormat.Html);
index.highlight(document, highlighter, options);
// 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) {
System.out.println(container.getFieldName());
System.out.println();
for (int j = 0; j < fragments.length; j++) {
// Printing HTML markup to console
System.out.println(fragments[j]);
System.out.println();
}
}
}
core| Constructor and Description |
|---|
FragmentHighlighter(OutputFormat outputFormat)
Initializes a new instance of the
FragmentHighlighter class. |
| Modifier and Type | Method and Description |
|---|---|
FragmentContainer[] |
getResult()
Gets an array of resulting fragment containers.
|
getCore, getOutputFormatclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetOutputFormatpublic FragmentHighlighter(OutputFormat outputFormat)
FragmentHighlighter class.outputFormat - The output format.public final FragmentContainer[] getResult()
getResult in interface IFragmentHighlighterCopyright © 2026. All rights reserved.