String resHighlSummary = null;
// Remove 'html', this works the same way as PageResponse.printNoHTML()
text = RegainToolkit.replace(text, "<", "<");
text = RegainToolkit.replace(text, ">", ">");
TokenStream tokenStream = mAnalyzer.tokenStream("content",
new StringReader(text));
// Get 3 best fragments and seperate with a " ... "
resHighlSummary = highlighter.getBestFragments(tokenStream, text, 3, " ... ");
if (resHighlSummary != null) {
//System.out.println("Highlighted summary: " + resHighlSummary);
// write the result back to the document in a new field
document.add(new Field("highlightedSummary", resHighlSummary, Field.Store.NO, Field.Index.NOT_ANALYZED));
document.add(new Field("highlightedSummary", CompressionTools.compressString(resHighlSummary), Field.Store.YES));
}
}
// Highlight the title
text = document.get("title");
String resHighlTitle = null;
if (text != null) {
TokenStream tokenStream = mAnalyzer.tokenStream("content",
new StringReader(text));
// Get the best fragment
resHighlTitle = highlighter.getBestFragment(tokenStream, text);
}