[7588] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * Copyright 2011 Gasol Wu. PIXNET Digital Media Corporation. |
---|
| 4 | * All rights reserved. |
---|
| 5 | * |
---|
| 6 | * Redistribution and use in source and binary forms, with or without |
---|
| 7 | * modification, are permitted provided that the following conditions are met: |
---|
| 8 | * |
---|
| 9 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
| 10 | * this list of conditions and the following disclaimer. |
---|
| 11 | * |
---|
| 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
| 13 | * this listof conditions and the following disclaimer in the documentation |
---|
| 14 | * and/or other materials provided with the distribution. |
---|
| 15 | * |
---|
| 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" |
---|
| 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
| 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
| 26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
| 27 | * |
---|
| 28 | * The views and conclusions contained in the software and documentation are |
---|
| 29 | * those of the authors and should not be interpreted as representing official |
---|
| 30 | * policies, either expressed or implied, of the copyright holder. |
---|
| 31 | * |
---|
| 32 | * @copyright Copyright 2011 Gasol Wu <gasol.wu@gmail.com> |
---|
| 33 | * @license http://github.com/basdenooijer/solarium/raw/master/COPYING |
---|
| 34 | * @link http://www.solarium-project.org/ |
---|
| 35 | * |
---|
| 36 | * @package Solarium |
---|
| 37 | * @subpackage Client |
---|
| 38 | */ |
---|
| 39 | |
---|
| 40 | /** |
---|
| 41 | * Parse MoreLikeThis response data |
---|
| 42 | * |
---|
| 43 | * @package Solarium |
---|
| 44 | * @subpackage Client |
---|
| 45 | */ |
---|
| 46 | class Solarium_Client_ResponseParser_Terms extends Solarium_Client_ResponseParser |
---|
| 47 | { |
---|
| 48 | |
---|
| 49 | /** |
---|
| 50 | * Get result data for the response |
---|
| 51 | * |
---|
| 52 | * @param Solarium_Result_Terms $result |
---|
| 53 | * @return array |
---|
| 54 | */ |
---|
| 55 | public function parse($result) |
---|
| 56 | { |
---|
| 57 | $termResults = array(); |
---|
| 58 | |
---|
| 59 | $data = $result->getData(); |
---|
| 60 | $field = $result->getQuery()->getFields(); |
---|
| 61 | $fields = explode(',', $field); |
---|
| 62 | foreach ($fields as $field) { |
---|
| 63 | $field = trim($field); |
---|
| 64 | if (isset($data['terms'][$field])) { |
---|
| 65 | $terms = $data['terms'][$field]; |
---|
| 66 | for ($i = 0; $i < count($terms); $i += 2) { |
---|
| 67 | $termResults[$field][$terms[$i]] = $terms[$i + 1]; |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | $status = null; |
---|
| 73 | $queryTime = null; |
---|
| 74 | if (isset($data['responseHeader'])) { |
---|
| 75 | $status = $data['responseHeader']['status']; |
---|
| 76 | $queryTime = $data['responseHeader']['QTime']; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | return array( |
---|
| 80 | 'status' => $status, |
---|
| 81 | 'queryTime' => $queryTime, |
---|
| 82 | 'results' => $termResults, |
---|
| 83 | ); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | } |
---|