* @license http://github.com/basdenooijer/solarium/raw/master/COPYING * @link http://www.solarium-project.org/ * * @package Solarium * @subpackage Client */ /** * Parse document analysis response data * * @package Solarium * @subpackage Client */ class Solarium_Client_ResponseParser_Analysis_Field extends Solarium_Client_ResponseParser { /** * Parse response data * * @param Solarium_Result $result * @return array */ public function parse($result) { $data = $result->getData(); if (isset($data['analysis'])) { $items = $this->_parseAnalysis($data['analysis']); } else { $items = array(); } return array( 'status' => $data['responseHeader']['status'], 'queryTime' => $data['responseHeader']['QTime'], 'items' => $items ); } /** * Parser * * @param array $data * @return array */ protected function _parseAnalysis($data) { $types = array(); foreach ($data as $documentKey => $documentData) { $fields = $this->_parseTypes($documentData); $types[] = new Solarium_Result_Analysis_List($documentKey, $fields); } return $types; } /** * Parse analysis types and items * * @param array $typeData * @return array */ protected function _parseTypes($typeData) { $results = array(); foreach ($typeData as $fieldKey => $fieldData) { $types = array(); foreach ($fieldData as $typeKey => $typeData) { // fix for extra level for key fields if (count($typeData) == 1) { $typeData = current($typeData); } $counter = 0; $classes = array(); while (isset($typeData[$counter]) && isset($typeData[$counter+1])) { $class = $typeData[$counter]; $analysis = $typeData[$counter+1]; if (is_string($analysis)) { $item = new Solarium_Result_Analysis_Item( array( 'text' => $analysis, 'start' => null, 'end' => null, 'position' => null, 'positionHistory' => null, 'type' => null, ) ); $classes[] = new Solarium_Result_Analysis_List($class, array($item)); } else { $items = array(); foreach ($analysis as $itemData) { $items[] = new Solarium_Result_Analysis_Item($itemData); } $classes[] = new Solarium_Result_Analysis_List($class, $items); } $counter += 2; } $types[] = new Solarium_Result_Analysis_List($typeKey, $classes); } $results[] = new Solarium_Result_Analysis_Types($fieldKey, $types); } return $results; } }