lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Anshum <ansh...@gmail.com>
Subject Re: Pagination and Sorting
Date Thu, 01 Oct 2009 12:30:47 GMT
@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_usenet@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-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message