lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Lea <>
Subject Re: Picking single results out of a list of results
Date Mon, 17 Oct 2011 09:21:41 GMT
The Hits class was deprecated at some point and has been removed from
recent releases.

The 2.9.3 javadoc at
shows a little code sample

TopDocs topDocs =, numHits);
   ScoreDoc[] hits = topDocs.scoreDocs;
   for (int i = 0; i < hits.length; i++) {
     int docId = hits[i].doc;
     Document d = searcher.doc(docId);
     // do something with current hit

you just need to replace numHits with a suitable value e.g. 1223 and
replace the for loop with something like

     int docId = hits[57].doc;
     Document d57 = searcher.doc(docId);
     docId = hits[1223].doc;
     Document d1223 = searcher.doc(docId);

Higher values for numHits may have adverse effects on performance, but
if you need them, you need them.


On Sat, Oct 15, 2011 at 7:47 PM, Herb Roitblat <> wrote:
> I have an application where I would like to pick one document from somewhere
> in the list of search results.  For example, I would like to retrieve one of
> the results at rank 57, another at rank 1223, etc.  I'm not real clear on
> how to do it.
> I have seen some things on simulating pagination with Lucene, some code on
> using hitlists and some comments on hitlists being deprecated.
> I have seen the class TopDocsCollector and the method
> |*topDocs
> <,%20int%29>*(int
> start, int howMany)|
>          Returns the documents in the rage [start ..
> I can see using topDocs with howMany = 1, but I'm wondering whether that
> means that the system iterates over the entire return list until it finds
> the the one at rank start?
> Is this the best way to do it?
> I'm using pyLucene 2.9 on Ubuntu 10.04.
> Thanks for any pointers.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message