我的lucene 4.6的分页、排序代码是:
private ScoreDoc getLastScoreDoc(int pageNum,int pageRecord,Query query,IndexSearcher searcher,Sort sort) throws IOException {
if(pageNum==1)return null;//如果是第一页就返回空
int num = pageRecord*(pageNum-1);//获取上一页的最后数量
TopDocs tds = searcher.search(query, num,sort);
return tds.scoreDocs[num-1];
}
/**
* 标题查询匹配的分页数据
* @param query
* @param pageNum
* @param pageRecord
* @return Page 单页Page对象
*/
public Page singleSearchPageByAfter(String queryStr,int pageNum,int pageRecord) {
List<WenDu> pagelist=null;
Page page=null;
try {
Directory directory = FSDirectory.open(new File(indexdir));
IndexReader reader = IndexReader.open(directory);
IndexSearcher searcher = new IndexSearcher(reader);