Hi Anshum, That is exactly the same code he is using (only that he does not instantiate the collector; IndexSearcher.search(query, int) does exactly that internally :-)
His problem was, that if offset+limit is large or Integer.MAX_VALUE that he runs out of memory. ----- Uwe Schindler H.-H.-Meier-Allee 63, D-28213 Bremen http://www.thetaphi.de eMail: u...@thetaphi.de > -----Original Message----- > From: Anshum [mailto:ansh...@gmail.com] > Sent: Thursday, October 01, 2009 2:31 PM > To: java-user@lucene.apache.org > Subject: Re: Pagination and Sorting > > @Christian : Which version of Lucene are you using? > > For lucene 2.9 this would work. > *__code snippet__* > IndexReader r = IndexReader.open("/home/anshum/index/indexname", true); > IndexSearcher s = new IndexSearcher(r); > QueryParser qp = new QueryParser("testfield",new StopAnalyzer()); > Query q = qp.parse("test query"); > int offset = 10000; > int limit = 100; > Sort sort = new Sort(new SortField("testfield",SortField.DOUBLE));* // You > may want to change field type to something else* > TopFieldCollector c = TopFieldCollector.create(sort, offset+limit, true, > true, true, true); > s.search(q, c); > for(int i=offset;i<offset + limit;i++) > System.out.println("Document : " + > s.doc(c.topDocs().scoreDocs[i].doc)); > > *__code snippet ends__* > -- > Anshum Gupta > Naukri Labs! > http://ai-cafe.blogspot.com > > The facts expressed here belong to everybody, the opinions to me. The > distinction is yours to draw............ > > > On Thu, Oct 1, 2009 at 5:37 PM, Christian Robert <cr_use...@arcor.de> > wrote: > > > Anshum, > > > > > You could get the hits in a collector and pass the sort to the > > > collector as it would be the collect function that handles the > > > sorting. > > > > > > searcherObject.search(query,collector); > > > > > > Hope that gives you some headway. :) > > > > Not quite (yet?) ;-) > > > > What do you mean by passing the Sort to the collector as collect > > function? Could you provide a little code snippet that describes > > the procedure? > > > > Thanks! > > Chris > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org > > For additional commands, e-mail: java-user-h...@lucene.apache.org > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org