Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter(
"red", ""), new QueryScorer(query));
highlighter.setTextFragmenter(new SimpleFragmenter(10));
Analyzer analyzer = new IK_CAnalyzer();
for (int i = 0; i < hits.length(); i++) {
String text = hits.doc(i).get("contents");
TokenStream tokenStream = analyzer.tokenStream("contents",
new StringReader(text));
String result = highlighter.getBestFragments(tokenStream, text, 4,
"");//对查找到的文件进行加亮处理(用【】包含起来)
System.out.println(" 与查询相关内容为:"+"/n"+result);
System.out.println("文件为:"+hits.doc(i).get("filename"));
}
"red", ""), new QueryScorer(query));
highlighter.setTextFragmenter(new SimpleFragmenter(10));
Analyzer analyzer = new IK_CAnalyzer();
for (int i = 0; i < hits.length(); i++) {
String text = hits.doc(i).get("contents");
TokenStream tokenStream = analyzer.tokenStream("contents",
new StringReader(text));
String result = highlighter.getBestFragments(tokenStream, text, 4,
"");//对查找到的文件进行加亮处理(用【】包含起来)
System.out.println(" 与查询相关内容为:"+"/n"+result);
System.out.println("文件为:"+hits.doc(i).get("filename"));
}