* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @link http://www.solarium-project.org/ * * @package Solarium * @subpackage Client */ /** * Parse select response data * * @package Solarium * @subpackage Client */ class Solarium_Client_ResponseParser_Select extends Solarium_Client_ResponseParser { /** * Get result data for the response * * @param Solarium_Result_Select $result * @return array */ public function parse($result) { $data = $result->getData(); $query = $result->getQuery(); // create document instances $documentClass = $query->getOption('documentclass'); $documents = array(); if (isset($data['response']['docs'])) { foreach ($data['response']['docs'] AS $doc) { $fields = (array)$doc; $documents[] = new $documentClass($fields); } } // component results $components = array(); $types = $query->getComponentTypes(); foreach ($query->getComponents() as $component) { $componentParserClass = $types[$component->getType()]['responseparser']; if (!empty($componentParserClass)) { $componentParser = new $componentParserClass; $components[$component->getType()] = $componentParser->parse($query, $component, $data); } } if (isset($data['response']['numFound'])) { $numFound = $data['response']['numFound']; } else { $numFound = null; } $status = null; $queryTime = null; if (isset($data['responseHeader'])) { $status = $data['responseHeader']['status']; $queryTime = $data['responseHeader']['QTime']; } return array( 'status' => $status, 'queryTime' => $queryTime, 'numfound' => $numFound, 'documents' => $documents, 'components' => $components, ); } }