lucene 高亮截取文章不全

阅读更多

lucene3.5设置高亮时 出现文本显现不完全
解决方法:加入如下代码  设定字符串的长度;


//highlighter.setTextFragmenter(new SimpleFragmenter(s.length()));


public static String Highlighter(Query query, String s, String field)
throws IOException, InvalidTokenOffsetsException {

SimpleHTMLFormatter simpleHtmlFormatter = new SimpleHTMLFormatter(
"", "");
Highlighter highlighter = new Highlighter(simpleHtmlFormatter,
new QueryScorer(query));
highlighter.setTextFragmenter(new SimpleFragmenter(s.length()));

TokenStream tokenStream = analyzer.tokenStream(field, new StringReader(
s));
String highlighterStr = highlighter.getBestFragment(tokenStream, s);
return highlighterStr == null ? s : highlighterStr;

}


你可能感兴趣的:(lucene)