lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael McCandless <luc...@mikemccandless.com>
Subject Re: Returning hits by highest score
Date Wed, 17 Dec 2008 13:59:27 GMT

Right, it returns the best 10 documents by score (not the first 10  
docs it sees).

You could also simply use the search(Query, int) method too (which  
just creates the TopDocCollector under the hood).

Mike

Danil Ε’ORIN wrote:

> According to http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/TopDocCollector.html
> it does.
>
> After search, simple retrieve TopDocs and read documens you need:
>
> List<Document> result = new ArrayList<Document>(10);
> for( ScoreDoc sDoc :collector.topDocs().scoreDocs) {
>    result.add(contentSearcher.doc(sDoc.doc));
> }
>
> And use result.
>
> On Wed, Dec 17, 2008 at 13:36, Chris Bamford  
> <chris.bamford@scalix.com> wrote:
>> Hi
>>
>> In a search I am doing, there may be thousands of hits, of which I  
>> only want
>> the 10 with the highest score. Will the following code do this for  
>> me, or
>> will it simply return the first 10 it finds?
>>
>> TopDocCollector collector = new TopDocCollector(10);
>> contentSearcher.search(q, collector);
>>
>> If the latter case is true (i.e. the first 10 are returned), how  
>> can I get
>> it to do what I want?
>>
>> Thanks,
>>
>> - Chris
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message