lucene 分页

/**
* 获取指定范围内的文档(该方法只打印文档内容,代表取得相应的文档)。
*
@param start 注意:从0开始计数
*
@param howMany
*/
public void getResults(int start , int howMany) {
try {
QueryParser parser
= new QueryParser(Version.LUCENE_30, "f", new StandardAnalyzer(Version.LUCENE_30));
Query query
= parser.parse("a:fox");
//
TopScoreDocCollector results = TopScoreDocCollector.create(start+howMany, false);
searcher.search(query, results);
TopDocs tds
= results.topDocs(start, howMany);
ScoreDoc[] sd
= tds.scoreDocs;
for (int i = 0; i < sd.length; i++) {
System.out.println(reader.document(sd[i].doc));
}
}
catch (IOException e) {
e.printStackTrace();
}
catch (ParseException e) {
e.printStackTrace();
}
}
<!--EndFragment-->

你可能感兴趣的:(Lucene)