Lucene学习笔记4--建立分页
List<Object>list=newArrayList<Object>();
//定义每次显示的搜索结果数目
finalintHITS_PER_PAGE=10;
intcount=h.length();
for(intstart=0;start<h.length();start+=HITS_PER_PAGE){
intend=Math.min(h.length(),start+HITS_PER_PAGE);
for(inti=start;i<end;i++){
//打印出文件里面ArticleTitle域里面的内容
Stringtitle=h.doc(i).get(ArticleTitle);
//打印出文件里面ArticleText域里面的内容
Stringtext=h.doc(i).get(ArticleText);
//搜索结果高亮显示
SimpleHTMLFormatterformat=newSimpleHTMLFormatter("<b><fontcolor='red'>","</font></b>");
Highlighterlight=newHighlighter(format,newQueryScorer(multiQuery));//高亮
light.setTextFragmenter(newSimpleFragmenter(200));
//为了在页面好遍历,把它放入集合中
if(title!=null||text!=null){
TokenStreamstream=analyzer.tokenStream(ArticleTitle,newStringReader(title));
highTitle=light.getBestFragment(stream,title);
TokenStreamstreamText=analyzer.tokenStream(ArticleText,newStringReader(text));
highText=light.getBestFragment(streamText,text);
LuceneBeanbean=newLuceneBean();
bean.setNum(i+1);
bean.setTitle(null!=highTitle?highTitle:title);
bean.setText(null!=highText?highText:text);
bean.setTime(h.doc(i).get(ArticleTime));
list.add(bean);
}
}
break;
}
/*关闭*/
searcher.close();