Use IndexSearcher.searchAfter
Skip Previous Docs
Not good at performance and memory usage.
In Solr4.7, we can do deep paging with cursorMark
Solr Deep Pagination Problem Fixed in Solr-5463
Sorting, Paging, and Deep Paging in Solr
http://solr1:8080/solr/select?q=accesstime:[* TO NOW-5YEAR/DAY]&sort=accesstime desc, contentid asc&sort=accesstime desc,id asc&rows=1000&start=0&cursorMark=*
http://solr1:8080/solr/select?q=accesstime:[* TO NOW-5YEAR/DAY]&sort=accesstime desc, contentid asc&sort=accesstime desc,id asc&rows=1000&start=0&cursorMark=AoJ42tmu%2FZ4CKTQxMDMyMzEwMw%3D%3D
/** * useSearcherAfter, need client record the returned last ScoreDoc * lastBottom, and pass it in next round. */ private void useSearcherAfter(DirectoryReader indexReader, IndexSearcher searcher, int pageSize) throws IOException { Query query = new TermQuery(new Term("title", "java")); // query = new MatchAllDocsQuery(); ScoreDoc lastBottom = null; while (true) { TopDocs paged = null; paged = searcher.searchAfter(lastBottom, query, null, pageSize); if (paged.scoreDocs.length == 0) { // no more data, break; break; } ScoreDoc[] scoreDocs = paged.scoreDocs; for (ScoreDoc scoreDoc : scoreDocs) { Utils.printDoc(searcher.doc(scoreDoc.doc), "id", "title"); } lastBottom = paged.scoreDocs[paged.scoreDocs.length - 1]; } }
Skip Previous Docs
Not good at performance and memory usage.
private void skipPreviousRows(DirectoryReader indexReader, IndexSearcher searcher, int pageStart, int pageSize) throws IOException { Query query = new TermQuery(new Term("title", "java")); int pageEnd = pageStart - 1 + pageSize; TopDocs hits = searcher.search(query, pageEnd); for (int i = pageStart - 1; i < pageEnd; i++) { int docId = hits.scoreDocs[i].doc; // load the document Document doc = searcher.doc(docId); Utils.printDocAndExplain(doc, searcher, query, docId, "id", "title"); } }
In Solr4.7, we can do deep paging with cursorMark
Solr Deep Pagination Problem Fixed in Solr-5463
Sorting, Paging, and Deep Paging in Solr
http://solr1:8080/solr/select?q=accesstime:[* TO NOW-5YEAR/DAY]&sort=accesstime desc, contentid asc&sort=accesstime desc,id asc&rows=1000&start=0&cursorMark=*
http://solr1:8080/solr/select?q=accesstime:[* TO NOW-5YEAR/DAY]&sort=accesstime desc, contentid asc&sort=accesstime desc,id asc&rows=1000&start=0&cursorMark=AoJ42tmu%2FZ4CKTQxMDMyMzEwMw%3D%3D