個人認為最好每一次分頁導航都執行一次新的 查詢。
[color=red]lucene舊版本中常用方法:[/color]
hits中儲存的並不是真正的document,因此可以通過hits.doc(index)的方式取出在一定範圍內的document。在獲 得hits後可以用類似下面的方法進行分頁處理:
private list proces****s(hits hits,int startindex,int endindex)throws exception
return docs;
}
這裡可以按自己的需要重新封裝document和field的資料。startindex和endindex標定了當前頁面的範圍。
lucene新版本中hits已經被棄用,代替它的是topdocs,具體分頁查詢的方法為:
topdocs topdocs=indexsearcher.search(query, 10000);
scoredoc scoredocs=topdocs.scoredocs;
//儲存符合條件的記錄
arraylistlist=new arraylist();
for (int i = startindex;i < endindex&&i
Lucene3 6的分頁查詢
分頁查詢只需要傳入每頁顯示多少條記錄,當前是第幾頁就可以了。當然是對搜尋返回的結果進行分頁,並不是對搜尋結果的總數量進行分頁,因為我們搜尋的時候都是返回前n條記錄。例如indexsearcher.search query,100 只返回前100條記錄 對搜尋返回的前n條結果進行分頁顯示 param ...
lucene 排序 分頁
private string searchdir null private static file indexfile null 讀取索引檔案 return throws exception private indexsearcher getsearcher throws exception 中文分...
Lucene分頁方式
推薦的做法是為每一次分頁導航都執行一次新的 查詢。因為hits中儲存的並不是真正的document,因此可以通過hits.doc index 的方式取出在一定範圍內的document。在獲 得hits後可以用類似下面的方法進行分頁處理 private list proces s hits hits,...