You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Christian Reuschling <ch...@gmail.com> on 2009/10/15 18:41:35 UTC

How to sort and get document scores afterwards

Hi,

our application enables sorting the result lists according to field values,
currently all represented as Strings (we plan to also migrate to the new
numeric type capabilities of Lucene 2.9 at a later time)

For this, the documents will be sorted e.g. according to the author, which
works fine with the new 2.9 sort interface


llSortFields.add(new SortField(strFieldName4Sorting, SortField.STRING, !bAscending));

topDocs = searcher.search(wheight4Query, (Filter) null, m_iMaxTopDocs, new Sort(llSortFields.toArray(new SortField[0])));

for (ScoreDoc scoreDoc : m_luceneTopDocs.scoreDocs)
   System.out.println(scoreDoc.score);  //>>>>>> NaN


Nevertheless, we visualize the score of each document inside a birdeye view, to show the relevancy of each doc according to
the users query. But the scoreDoc.score  numbers have all the value 'NaN'.

This is a new behaviour in Lucene 2.9, I think a good feature to save cpu time - but how can we get the scores again?


regards


Chris


RE: How to sort and get document scores afterwards

Posted by Uwe Schindler <uw...@thetaphi.de>.
The default API searcher.search works like this now. If you want to control,
the retrieval of scores, create a TopFieldCollector directly:
http://lucene.apache.org/java/2_9_0/api/all/org/apache/lucene/search/TopFiel
dCollector.html

The static create methods has many possibilities to control the behaviour of
the resulting Collector. Pass this collector to the corresponding search
engine. The topDocs() method returns the resulting TopDocs instance (its in
the superclass TopDocsCollector!!!). Some hints: mostly scoreDocsInOrder can
be false, if you need the maxScore set it true, you want to have scores, so
set also to true. Mosly you will not need the sorted field values (false).

Uwe

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de

> -----Original Message-----
> From: Christian Reuschling [mailto:christian.reuschling@gmail.com]
> Sent: Thursday, October 15, 2009 6:42 PM
> To: java-user@lucene.apache.org
> Subject: How to sort and get document scores afterwards
> 
> Hi,
> 
> our application enables sorting the result lists according to field
> values,
> currently all represented as Strings (we plan to also migrate to the new
> numeric type capabilities of Lucene 2.9 at a later time)
> 
> For this, the documents will be sorted e.g. according to the author, which
> works fine with the new 2.9 sort interface
> 
> 
> llSortFields.add(new SortField(strFieldName4Sorting, SortField.STRING,
> !bAscending));
> 
> topDocs = searcher.search(wheight4Query, (Filter) null, m_iMaxTopDocs, new
> Sort(llSortFields.toArray(new SortField[0])));
> 
> for (ScoreDoc scoreDoc : m_luceneTopDocs.scoreDocs)
>    System.out.println(scoreDoc.score);  //>>>>>> NaN
> 
> 
> Nevertheless, we visualize the score of each document inside a birdeye
> view, to show the relevancy of each doc according to
> the users query. But the scoreDoc.score  numbers have all the value 'NaN'.
> 
> This is a new behaviour in Lucene 2.9, I think a good feature to save cpu
> time - but how can we get the scores again?
> 
> 
> regards
> 
> 
> Chris



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


Re: How to sort and get document scores afterwards

Posted by Michael McCandless <lu...@mikemccandless.com>.
Yeah this was a change in 2.9... but you can get the scores back, if
you do this:

      TopFieldCollector tfc = TopFieldCollector.create(sort, numHits,
fillFields,
                                                       true /*
trackDocScores */,
                                                       true /* trackMaxScore */,
                                                       false /* docsInOrder */);
      searcher.search(query, tfc);
      TopDocs results = tfc.topDocs();

Mike

On Thu, Oct 15, 2009 at 12:41 PM, Christian Reuschling
<ch...@gmail.com> wrote:
> Hi,
>
> our application enables sorting the result lists according to field values,
> currently all represented as Strings (we plan to also migrate to the new
> numeric type capabilities of Lucene 2.9 at a later time)
>
> For this, the documents will be sorted e.g. according to the author, which
> works fine with the new 2.9 sort interface
>
>
> llSortFields.add(new SortField(strFieldName4Sorting, SortField.STRING, !bAscending));
>
> topDocs = searcher.search(wheight4Query, (Filter) null, m_iMaxTopDocs, new Sort(llSortFields.toArray(new SortField[0])));
>
> for (ScoreDoc scoreDoc : m_luceneTopDocs.scoreDocs)
>   System.out.println(scoreDoc.score);  //>>>>>> NaN
>
>
> Nevertheless, we visualize the score of each document inside a birdeye view, to show the relevancy of each doc according to
> the users query. But the scoreDoc.score  numbers have all the value 'NaN'.
>
> This is a new behaviour in Lucene 2.9, I think a good feature to save cpu time - but how can we get the scores again?
>
>
> regards
>
>
> Chris
>
>

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