Hi Jawahar, http://search-lucene.com/m/duTpc14AmzV See Uwe's reply.
Regards Umesh PS: I would use search-lucene.com to 1st check if a solution is posted already. It is really good. ------------------------ QUOTED UWE's reply ---------------------- To get the second page, Take: int hitsPerPage = 10; int pageOffset = 10; TopDocCollector collector = new TopDocCollector(hitsPerPage + pageOffset); For page third page take int pageOffset = 20; and so on After that your results are in hits[], for the first page in [0] to [9], the second page in [10] to [19] and so on: To display use something like: For (int i=pageOffset; Math.min(hitsPerPage + pageOffset, collector.topDocs().totalhits); i++) In general, you cannot retrieve a range directly, you can only retrieve the top docs. As most people will not go beyond say page 10 when searching, you have no memory problem, as scoreDocs will contain at most 100 doc ids. --------------- ------------------- On Fri, Dec 24, 2010 at 10:40 AM, Jawahar Lal <j...@chambal.com> wrote: > Hi, > > I search for an query. Total searched records are 5000. I only shows 100 > records on one page. So I passed 100 as nDocs. > > I write the code in this way. > > IndexSearcher searcher = new IndexSearcher(FSDirectory.open(new > File(path))); > > Query query = new QueryParser(Version.LUCENE_30, "field1", new > StandardAnalyzer(Version.LUCENE_30)).parse("query"); > Query query1 = new QueryParser(Version.LUCENE_30, "field2", new > StandardAnalyzer(Version.LUCENE_30)).parse("query2"); > BooleanQuery lucBoolQueryOTHER = new BooleanQuery(); > lucBoolQueryOTHER.add(query, Occur.MUST); > lucBoolQueryOTHER.add(query1, Occur.MUST); > > TopDocs hits=searcher.search(query, null, 100); > > System.err.println("Total searched " + hits.totalHits); >> > 5000 > System.err.println("Total docs " + hits.scoreDocs.length); >> > 100 > > // The code to print 100 records on first page > for(int i=0;i<hits.scoreDocs.length;i++){ > > > System.out.println(searcher.doc(hits.scoreDocs[i].doc).getField("filename")); > } > > it worked fine. > > // Now I want to show all next search documents on Second Pages...when I > tried in this way, I got the error. > for(int i=100;i<hits.totalHits;i++){ > > > System.out.println(searcher.doc(hits.scoreDocs[i].doc).getField("filename")); > } > > searcher.close(); > > java.lang.ArrayIndexOutOfBoundsException: 100 > at Test.searchIndex(Test.java:96) > at Test.main(Test.java:54) > > Would need to perform searching again with different parameters to fetch > next bunch of records ? > > > > > Thanks > -- --- Thanks & Regards Umesh Prasad