You are here

protected function Apache_Solr_Response::_parseData in Apache Solr Search 5

Parse the raw response into the parsed_data array for access

1 call to Apache_Solr_Response::_parseData()
Apache_Solr_Response::__get in SolrPhpClient/Apache/Solr/Response.php
Magic get to expose the parsed data and to lazily load it

File

SolrPhpClient/Apache/Solr/Response.php, line 221

Class

Apache_Solr_Response
Represents a Solr response. Parses the raw response into a set of stdClass objects and associative arrays for easy access.

Code

protected function _parseData() {

  //An alternative would be to use Zend_Json::decode(...)
  $data = json_decode($this->_rawResponse);

  //if we're configured to collapse single valued arrays or to convert them to Apache_Solr_Document objects

  //and we have response documents, then try to collapse the values and / or convert them now
  if (($this->_createDocuments || $this->_collapseSingleValueArrays) && isset($data->response) && is_array($data->response->docs)) {
    $documents = array();
    foreach ($data->response->docs as $originalDocument) {
      if ($this->_createDocuments) {
        $document = new Apache_Solr_Document();
      }
      else {
        $document = $originalDocument;
      }
      foreach ($originalDocument as $key => $value) {

        //If a result is an array with only a single

        //value then its nice to be able to access

        //it as if it were always a single value
        if ($this->_collapseSingleValueArrays && is_array($value) && count($value) <= 1) {
          $value = array_shift($value);
        }
        $document->{$key} = $value;
      }
      $documents[] = $document;
    }
    $data->response->docs = $documents;
  }
  $this->_parsedData = $data;
}