lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ramy Hardan <>
Subject Re: Limiting hit count
Date Fri, 13 Feb 2004 18:34:43 GMT

> ...I actually only want the first hit
If you say you want the first hit, do you mean any hit or the one
that's usually first in Hits? The latter is the one with the highest
score, so interrupting the search won't help you, since you don't know
when the highest score is reached before examining all documents.

> On Friday 13 February 2004 15:02, Erik Hatcher wrote:
>> Use a HitCollector and grab the first one that comes in, then bail out.
>>   That should do the trick for getting the first hit only.

> According to the API docs I ought to use HitCollector only if I need all
> hits :-) And there's certainly a reason for it - I don't think that this will
> speed up the search ;)
I agree that bailing out of the HitCollector is a bad idea, because
the only way to achieve this is to throw an exception. Probably Lucene
finishes searching, creates the Hits object and cooks a meal long
before the VM is able to build the stack trace and execute your catch
clause ;)


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

View raw message