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_MoreLikeThis extends Solarium_Client_ResponseParser_Select |
---|
47 | { |
---|
48 | |
---|
49 | /** |
---|
50 | * Get result data for the response |
---|
51 | * |
---|
52 | * @param Solarium_Result_MoreLikeThis $result |
---|
53 | * @return array |
---|
54 | */ |
---|
55 | public function parse($result) |
---|
56 | { |
---|
57 | $data = $result->getData(); |
---|
58 | $query = $result->getQuery(); |
---|
59 | |
---|
60 | $parseResult = parent::parse($result); |
---|
61 | if (isset($data['interestingTerms']) && 'none' != $query->getInterestingTerms()) { |
---|
62 | $terms = $data['interestingTerms']; |
---|
63 | if ('details' == $query->getInterestingTerms()) { |
---|
64 | $tempTerms = array(); |
---|
65 | for ($i = 0; $i < count($terms); $i += 2) { |
---|
66 | $tempTerms[$terms[$i]] = $terms[$i + 1]; |
---|
67 | } |
---|
68 | $terms = $tempTerms; |
---|
69 | } |
---|
70 | $parseResult['interestingTerms'] = $terms; |
---|
71 | } |
---|
72 | |
---|
73 | if (isset($data['match']['docs'][0]) && true == $query->getMatchInclude()) { |
---|
74 | $matchData = $data['match']['docs'][0]; |
---|
75 | |
---|
76 | $documentClass = $query->getOption('documentclass'); |
---|
77 | $fields = (array)$matchData; |
---|
78 | $parseResult['match'] = new $documentClass($fields); |
---|
79 | } |
---|
80 | |
---|
81 | return $parseResult; |
---|
82 | } |
---|
83 | |
---|
84 | } |
---|