String SearchText = request.getParameter(
"txtsearch").toString();
TermQuery query = new TermQuery(new Term("f",
SearchText));
QueryScorer scorer = new QueryScorer(query);
SimpleHTMLFormatter formatter = new SimpleHTMLFormatter(
"<span class=\"highlight\">", "</span>");
org.apache.lucene.search.highlight.Highlighter highlighter = new org.apache.lucene.search.highlight.Highlighter(
formatter, scorer);
Fragmenter fragmenter = new SimpleFragmenter(
result.length());
highlighter.setTextFragmenter(fragmenter);
TokenStream tokenStream = new SnowballAnalyzer(
"English").tokenStream("f",
new StringReader(result));
String result1 = highlighter.getBestFragments(
tokenStream, result, 5, "...");
if (result1.length() == 0) {
result1 = result;
}
finalhtml = "<html>" + "<style>\n"
+ ".highlight{\n"
+ " background: yellow;\n" + "}\n"
+ "</style>" + "<body>" + result1
+ "</body></html>";
这是我的 Lucene 高亮代码。结果是我的 Html 和 Searchtext 是我的文本搜索,它是动态的请检查我的代码哪里做错了一些选定的词是一个高度突出,如税、德里、加尔各答等我不知道哪里做错了请帮助我