Hello there Mark!
With SolrJ, you can simply do the following:
server.query(q) returns QueryResponse

the queryResponse has the method getResults() which returns SolrDocumentList. This is an extended list containing SolrDocuments, but it also exposes methods such as getNumFound(), which is exactly what you are looking for!

so, you could do something like this:
int hits = solrServer.query(q).getResults().getNumFound();

and you have similar methods for the other attributes, like:
results.getMaxScore();
and
results.getStart();

Hope that helps.

Cheers, and merry Christmas!
 Aleks

On Fri, 19 Dec 2008 21:22:48 +0100, Mark Ferguson <mark.a.fergu...@gmail.com> wrote:

Hello,

I am trying to get the numFound attribute from a returned QueryResponse
object, but for the life of me I can't find where it is stored. When I view a response in XML format, it is stored as an attribute on the response node,
e.g.:

<result name="response" numFound="207" start="5" maxScore="4.1191907">

However, I can't find a way to retrieve these attributes (numFound, start
and maxScore). When I look at the QueryResponse itself, I can see that the attributes are being stored somewhere, because the toString method returns
them. For example, queryResponse.toString() returns:

{responseHeader={status=0,QTime=139,params={wt=javabin,hl=true,rows=15,version=2.2,fl=urlmd5,start=0,q=java}},response={
*numFound=1228*,start=03.633028,docs=[SolrDocument[{urlmd5=...

The problem is that when I call queryResponse.get('response'), all I get is the list of SolrDocuments, I don't have any other attributes. Am I missing something or are these attributes just not publically available? If they're
not, shouldn't they be? Thanks a lot,

Mark Ferguson



--
Aleksander M. Stensby
Senior software developer
Integrasco A/S
www.integrasco.no

Please consider the environment before printing all or any of this e-mail

Reply via email to