php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59196 SolrClient::query() returns SolrObject instead of SolrQueryResponse instance
Submitted: 2010-05-07 13:50 UTC Modified: 2010-05-10 15:47 UTC
From: umesh_kant at rediffmail dot com Assigned: iekpo (profile)
Status: Not a bug Package: solr (PECL)
PHP Version: 5.2.6 OS: ubuntu4.5 with Suhosin-Patch 0.9
Private report: No CVE-ID: None
 [2010-05-07 13:50 UTC] umesh_kant at rediffmail dot com
Description:
------------
SolrClient::query() returns SolrObject instead of 
SolrQueryResponse instance



Reproduce code:
---------------
$options = array
(
    'hostname' => localhost,
    'login'    => ,
    'password' => ,
    'port'     => 8983,
);

$client = new SolrClient($options);
$query = new SolrQuery();
$query->setQuery('*:*');
$query->setStart(0);
$query->setRows(50);
$query_response = $client->query($query);
$response = $query_response->getResponse();

Expected result:
----------------
$response should have the SolrObject instance containing the 
response.

Actual result:
--------------
line '$response = $query_response->getResponse();' throws 
error 'Fatal error: Call to undefined method 
SolrObject::getResponse() in......'

When tried to print $response, found that SolrClient::query() 
returns SolrObject where as as per documentation it should 
return SolrQueryResponse.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-07 17:25 UTC] iekpo@php.net
I am not able to reproduce this error, even in cases where there is no matches.

Also the SolrClient::query() method is only allowed to return objects of type SolrResponse. So your observation is very strange.

Could you call SolrClient::getDebug() so that I can see what you are sending and getting back from the server?
 [2010-05-10 10:51 UTC] umesh_kant at rediffmail dot com
Right after I get the response from solr, I called 
getDebug() method. But it is returning NULL. I print both 
the response and getDebug using Zend_Debug::dump() and see 
following:

RESPONSE
---------------

object(SolrObject)#88 (2) {
  ["responseHeader"] => object(SolrObject)#89 (3) {
    ["status"] => int(0)
    ["QTime"] => int(0)
    ["params"] => object(SolrObject)#90 (7) {
      ["sort"] => string(15) "a_name_sort asc"
      ["indent"] => string(2) "on"
      ["start"] => string(1) "0"
      ["q"] => string(20) "a_name_firstLetter:B"
      ["wt"] => string(3) "xml"
      ["version"] => string(3) "2.2"
      ["rows"] => string(2) "20"
    }
  }
  ["response"] => object(SolrObject)#91 (3) {
    ["numFound"] => int(3)
    ["start"] => int(0)
    ["docs"] => array(3) {
      [0] => object(SolrObject)#92 (11) {
        ["a_matrix_description"] => string(22) "Band, with 
cornet solo"
        ["a_matrix_id"] => string(9) "200000600"
        ["a_matrix_title"] => string(11) "La danseuse"
        ["a_name"] => string(15) "Blon, Franz von"
        ["a_name_firstLetter"] => string(1) "B"
        ["a_name_sort"] => string(15) "Blon, Franz von"
        ["a_role"] => string(3) "cmp"
        ["a_role_sort"] => string(3) "cmp"
        ["a_talent_id"] => string(5) "40835"
        ["id"] => string(12) "Artist:40835"
        ["s_type"] => string(6) "Artist"
      }
      [1] => object(SolrObject)#93 (11) {
        ["a_matrix_description"] => string(31) "Male vocal 
duet, with orchestra"
        ["a_matrix_id"] => string(9) "200000500"
        ["a_matrix_title"] => string(12) "Baffin's Bay"
        ["a_name"] => string(15) "Bryan, Vincent "
        ["a_name_firstLetter"] => string(1) "B"
        ["a_name_sort"] => string(15) "Bryan, Vincent "
        ["a_role"] => string(3) "lyr"
        ["a_role_sort"] => string(3) "lyr"
        ["a_talent_id"] => string(5) "40412"
        ["id"] => string(12) "Artist:40412"
        ["s_type"] => string(6) "Artist"
      }
      [2] => object(SolrObject)#94 (11) {
        ["a_matrix_description"] => string(4) "Band"
        ["a_matrix_id"] => string(9) "200000471"
        ["a_matrix_title"] => string(20) "John Anderson, my 
jo"
        ["a_name"] => string(13) "Burns, Robert"
        ["a_name_firstLetter"] => string(1) "B"
        ["a_name_sort"] => string(13) "Burns, Robert"
        ["a_role"] => string(3) "aut"
        ["a_role_sort"] => string(3) "aut"
        ["a_talent_id"] => string(5) "40176"
        ["id"] => string(12) "Artist:40176"
        ["s_type"] => string(6) "Artist"
      }
    }
  }
}
--------------------

getDebug()

-----------------
NULL
-----------------

Do I need to turn some setting on in SOLR config as well to 
enable debug info. I will search for any such setting and 
will post an update in case I have any success in getting 
the debug info.

Thanks,
Umesh
 [2010-05-10 11:01 UTC] umesh_kant at rediffmail dot com
Please close this bug as there is a problem with a wrapper 
that I am using. And code is working as per the 
documentation. Please accept my apologies.
 [2010-05-10 11:02 UTC] iekpo@php.net
What version of the SOLR extension are you using?

Also please could you send me the raw XML response obtained by querying Solr directly via the browser?

This will help me in my investigation.

Thanks.
 [2010-05-10 11:42 UTC] umesh_kant at rediffmail dot com
Hi,

We are using Solr client 0.9.9. Once again, I found the 
problem which was related to the way we were invoking the 
methods. So this was an error on my side. 

Although I have a question for you. In the debug info you 
can see below that digested response is empty. I am guessing 
that you will get the non empty digested response only when 
wt parameter is php/phps instead of default 'xml' value. 
Where can I set/change it to 'php'?

The debug info is as given below:

------------------------------------
string(1880) "About to connect() to localhost port 8983 (#0)
  Trying ::1... connected
Connected to localhost (::1) port 8983 (#0)
POST /solr/select/?wt=xml&version=2.2&indent=on HTTP/1.1
User-Agent: PHP Solr Client 0.9.9
Host: localhost:8983
Accept: */*
Accept-Charset: utf-8
Keep-Alive: 300
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 144

facet=true&facet.field=a_name_firstLetter&f.a_name_firstLett
er.facet.mincount=1&q=%2A%3A%2A&rows=0&start=0&f.a_name_firs
tLetter.facet.sort=indexHTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 1209
Server: Jetty(6.1.3)

<?xml version="1.0" encoding="UTF-8"?>
<response>

<lst name="responseHeader">
 <int name="status">0</int>
 <int name="QTime">17</int>
 <lst name="params">
  <str name="f.a_name_firstLetter.facet.sort">index</str>
  <str name="facet">true</str>
  <str name="indent">on</str>
  <str name="f.a_name_firstLetter.facet.mincount">1</str>
  <str name="start">0</str>
  <str name="q">*:*</str>
  <str name="facet.field">a_name_firstLetter</str>
  <str name="wt">xml</str>
  <str name="version">2.2</str>
  <str name="rows">0</str>
 </lst>
</lst>
<result name="response" numFound="773" start="0"/>
<lst name="facet_counts">
 <lst name="facet_queries"/>
 <lst name="facet_fields">
  <lst name="a_name_firstLetter">
	<int name="B">3</int>
	<int name="C">10</int>
	<int name="D">3</int>
	<int name="E">2</int>
	<int name="F">2</int>
	<int name="G">4</int>
	<int name="H">7</int>
	<int name="K">2</int>
	<int name="L">3</int>
	<int name="M">13</int>
	<int name="N">1</int>
	<int name="O">1</int>
	<int name="P">4</int>
	<int name="R">5</int>
	<int name="S">10</int>
	<int name="T">2</int>
	<int name="V">3</int>
	<int name="W">5</int>
	<int name="Y">1</int>
  </lst>
 </lst>
 <lst name="facet_dates"/>
</lst>
</response>
Connection #0 to host localhost left intact
"
---------------------------------
 [2010-05-10 11:45 UTC] umesh_kant at rediffmail dot com
The raw response is as given below:


["http_raw_response:protected"] => string(1209) "<?xml 
version="1.0" encoding="UTF-8"?>
<response>

<lst name="responseHeader">
 <int name="status">0</int>
 <int name="QTime">17</int>
 <lst name="params">
  <str name="f.a_name_firstLetter.facet.sort">index</str>
  <str name="facet">true</str>
  <str name="indent">on</str>
  <str name="f.a_name_firstLetter.facet.mincount">1</str>
  <str name="start">0</str>
  <str name="q">*:*</str>
  <str name="facet.field">a_name_firstLetter</str>
  <str name="wt">xml</str>
  <str name="version">2.2</str>
  <str name="rows">0</str>
 </lst>
</lst>
<result name="response" numFound="773" start="0"/>
<lst name="facet_counts">
 <lst name="facet_queries"/>
 <lst name="facet_fields">
  <lst name="a_name_firstLetter">
	<int name="B">3</int>
	<int name="C">10</int>
	<int name="D">3</int>
	<int name="E">2</int>
	<int name="F">2</int>
	<int name="G">4</int>
	<int name="H">7</int>
	<int name="K">2</int>
	<int name="L">3</int>
	<int name="M">13</int>
	<int name="N">1</int>
	<int name="O">1</int>
	<int name="P">4</int>
	<int name="R">5</int>
	<int name="S">10</int>
	<int name="T">2</int>
	<int name="V">3</int>
	<int name="W">5</int>
	<int name="Y">1</int>
  </lst>
 </lst>
 <lst name="facet_dates"/>
</lst>
</response>
"
  ["http_digested_response:protected"] => string(1) " "
 [2010-05-10 13:11 UTC] iekpo@php.net
This is a very interesting issue.

I would like to know how you are invoking the methods to get the observations that you are getting.

The protected http_digested_response property is always going to be empty because it is only populated and updated from the empty string " " after a call has been made to the getResponse() method.

Currently, the only valid value for the wt parameter is 'xml'. Any other value will not work because the SOLR extension expects all the response to be in version 2.2 of the XML format.

So you will not be able to change it at the moment to any other value until when the code has been modified to support alternative response formats.
 [2010-05-10 13:57 UTC] umesh_kant at rediffmail dot com
Hi,

The original issue 'getting instance of SolrObject instead 
of SolrQueryResponse' is invalid as inside a wrapper class 
what we were doing was something like:

public function execute()
{
$updateResponse = $this->_solrClient->query($this-
>_solrQuery);	
return $updateResponse->getResponse();
}

And in the controller we were calling execute method. This 
execute will always return the instance of SolrObject as 
SolrQueryResponse::getResponse() is being returned.

The original issue is not an issue. Thanks for explaining 
about wt, as of now it only supports xml. That means we are 
not going to get php serialized data using 
SolrResponse::getDigestedResponse() as of now?

Thanks,
Umesh
 [2010-05-10 14:35 UTC] iekpo@php.net
Hi Umesh,

The SolrResponse::getDigestedResponse() returns the value of the protected http_digested_response property which is only populated after a call to SolrResponse::getResponse().

See line 202 of the source code here
http://svn.php.net/viewvc/pecl/solr/tags/release_0_9_10/php_solr_response.c?view=markup


You can still get php serialized data using SolrResponse::getDigestedResponse() as of now (prepared internally by parsing the xml response). However, the SOLR extension checks if the returned value from SolrResponse::getResponse()is used so you have to point it to a valid variable as shown below : 

$response = $client->query($query);

$resp = $response->getResponse();

// php serialized data : a digest of xml response from Solr
$digested_response = $response->getDigestedResponse();

If the returned value from getResponse() is not used, then the call to getResponse() does nothing and the http_digested_response will not be populated since the response xml was not parsed.

See line 253 of the source code here

http://svn.php.net/viewvc/pecl/solr/tags/release_0_9_10/php_solr_response.c?view=markup

I hope this answers your question.
 [2010-05-10 14:37 UTC] iekpo@php.net
In summary,

If you need the digested response (serialized php data), just make a call to SolrResponse::getResponse() (make sure the returned value is used).

Then make another call to SolrResponse::getDigestedResponse() to retrieve the serialized php data
 [2010-05-10 15:47 UTC] iekpo@php.net
Closing this ticket.

This was a logic error in the user space code.
 [2011-01-19 04:52 UTC] kumar dot anuj8 at gmail dot com
Hi iekpo,
           When can we have options like php and phps to be 
incorporated in the solr library. Cause for using phpnative 
we have to specify classes to serialize the response. Solr 
has implemented response classes like php and phps but we 
don't have option to specify the same through the solr api.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 08:01:23 2020 UTC