You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Per Fredelius <pe...@gmail.com> on 2012/11/28 17:27:33 UTC

Access document scores from within a search component?

Hi all,

*The Question:*
How do I access the scoring from inside the search component? I can't find
it in either the responsebuilder or in the  solrQueryResponse. I can only
find document ids and I can ask if the result *hasScoring* (true)*.*

*Background (if needed):*
So I'm building myself a custom search component that plugs into the
default SearchHandler. From inside my component I want to work with the
search scoring supplied by the handler. I have put in the 'score' field
into the default parameters ('<str name="fl">*,score</str>) of the handler
so the scoring shows nicely in my response when I make a http query. (So it
shows client side but can't find in component)
Also, I added the component like so: (<arr
name="last-components"><str>mySearchComponent</str></arr>), so I assume it
means that the component is called after the scoring is done.

Currently I access the documents by having my component as
a NewSearcherListener, and using the - by 'inform' - supplied indexsearcher
to retrieve the documents pointed to by the doc ids that I can find in
responsebuilder.getResults().docList. This works well for retrieving fields
but not suprisingly, since I'm accessing the index directly, it
doesn't expose the scoring.

/Thanks!

Re: Access document scores from within a search component?

Posted by Per Fredelius <pe...@gmail.com>.
Thanks! I found out maybe an hour ago. Spent way to long looking for that.
Tried to trace where it was put into the response all the way up into
TopFieldCollector.java. That didn't make me any wiser though. :)

/ Per


2012/11/28 Chris Hostetter <ho...@fucit.org>

>
> : to retrieve the documents pointed to by the doc ids that I can find in
> : responsebuilder.getResults().docList. This works well for retrieving
> fields
> : but not suprisingly, since I'm accessing the index directly, it
> : doesn't expose the scoring.
>
> If you have a DocList where hasScores() returns true, then when you
> iterate over that DocList (using the DocIterator) the score() method will
> return the score for each doc.
>
>
> -Hoss
>

Re: Access document scores from within a search component?

Posted by Chris Hostetter <ho...@fucit.org>.
: to retrieve the documents pointed to by the doc ids that I can find in
: responsebuilder.getResults().docList. This works well for retrieving fields
: but not suprisingly, since I'm accessing the index directly, it
: doesn't expose the scoring.

If you have a DocList where hasScores() returns true, then when you 
iterate over that DocList (using the DocIterator) the score() method will 
return the score for each doc.


-Hoss