1 | <?php |
---|
2 | /** |
---|
3 | * Copyright 2011 Bas de Nooijer. All rights reserved. |
---|
4 | * |
---|
5 | * Redistribution and use in source and binary forms, with or without |
---|
6 | * modification, are permitted provided that the following conditions are met: |
---|
7 | * |
---|
8 | * 1. Redistributions of source code must retain the above copyright notice, |
---|
9 | * this list of conditions and the following disclaimer. |
---|
10 | * |
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
---|
12 | * this listof conditions and the following disclaimer in the documentation |
---|
13 | * and/or other materials provided with the distribution. |
---|
14 | * |
---|
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" |
---|
16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
---|
19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
25 | * POSSIBILITY OF SUCH DAMAGE. |
---|
26 | * |
---|
27 | * The views and conclusions contained in the software and documentation are |
---|
28 | * those of the authors and should not be interpreted as representing official |
---|
29 | * policies, either expressed or implied, of the copyright holder. |
---|
30 | */ |
---|
31 | |
---|
32 | class Solarium_Client_ResponseParser_Select_Component_DebugTest extends PHPUnit_Framework_TestCase |
---|
33 | { |
---|
34 | |
---|
35 | /** |
---|
36 | * @var Solarium_Client_ResponseParser_Select_Component_Debug |
---|
37 | */ |
---|
38 | protected $_parser; |
---|
39 | |
---|
40 | public function setUp() |
---|
41 | { |
---|
42 | $this->_parser = new Solarium_Client_ResponseParser_Select_Component_Debug(); |
---|
43 | } |
---|
44 | |
---|
45 | public function testParse() |
---|
46 | { |
---|
47 | $data = array( |
---|
48 | 'debug' => array( |
---|
49 | 'querystring' => 'dummy-qs', |
---|
50 | 'parsedquery' => 'dummy-pq', |
---|
51 | 'QParser' => 'dummy-qp', |
---|
52 | 'otherQuery' => 'dummy-oq', |
---|
53 | 'explain' => array( |
---|
54 | 'MA147LL/A' => array( |
---|
55 | 'match' => true, |
---|
56 | 'value' => 0.5, |
---|
57 | 'description' => 'fieldWeight(text:ipod in 5), product of:', |
---|
58 | 'details' => array( |
---|
59 | array( |
---|
60 | 'match' => true, |
---|
61 | 'value' => 0.5, |
---|
62 | 'description' => 'tf(termFreq(text:ipod)=1)', |
---|
63 | ) |
---|
64 | ), |
---|
65 | ), |
---|
66 | ), |
---|
67 | 'explainOther' => array( |
---|
68 | 'IW-02' => array( |
---|
69 | 'match' => true, |
---|
70 | 'value' => 0.6, |
---|
71 | 'description' => 'fieldWeight(text:ipod in 6), product of:', |
---|
72 | 'details' => array( |
---|
73 | array( |
---|
74 | 'match' => true, |
---|
75 | 'value' => 0.7, |
---|
76 | 'description' => 'tf(termFreq(text:ipod)=1)', |
---|
77 | ) |
---|
78 | ), |
---|
79 | ), |
---|
80 | ), |
---|
81 | 'timing' => array( |
---|
82 | 'time' => 36, |
---|
83 | 'prepare' => array( |
---|
84 | 'time' => 12, |
---|
85 | 'org.apache.solr.handler.component.QueryComponent' => array( |
---|
86 | 'time' => 1, |
---|
87 | ), |
---|
88 | 'org.apache.solr.handler.component.FacetComponent' => array( |
---|
89 | 'time' => 11, |
---|
90 | ), |
---|
91 | ), |
---|
92 | 'process' => array( |
---|
93 | 'time' => 8, |
---|
94 | 'org.apache.solr.handler.component.QueryComponent' => array( |
---|
95 | 'time' => 5, |
---|
96 | ), |
---|
97 | 'org.apache.solr.handler.component.MoreLikeThisComponent' => array( |
---|
98 | 'time' => 3, |
---|
99 | ), |
---|
100 | ) |
---|
101 | ) |
---|
102 | ) |
---|
103 | ); |
---|
104 | |
---|
105 | $result = $this->_parser->parse(null, null, $data); |
---|
106 | $this->assertEquals('dummy-qs', $result->getQueryString()); |
---|
107 | $this->assertEquals('dummy-pq', $result->getParsedQuery()); |
---|
108 | $this->assertEquals('dummy-qp', $result->getQueryParser()); |
---|
109 | $this->assertEquals('dummy-oq', $result->getOtherQuery()); |
---|
110 | |
---|
111 | $this->assertEquals(1, count($result->getExplain())); |
---|
112 | $doc = $result->getExplain()->getDocument('MA147LL/A'); |
---|
113 | $this->assertEquals(0.5, $doc->getValue()); |
---|
114 | $this->assertEquals(true, $doc->getMatch()); |
---|
115 | $this->assertEquals('fieldWeight(text:ipod in 5), product of:', $doc->getDescription()); |
---|
116 | $this->assertEquals( |
---|
117 | array(new Solarium_Result_Select_Debug_Detail(true, 0.5, 'tf(termFreq(text:ipod)=1)')), |
---|
118 | $doc->getDetails() |
---|
119 | ); |
---|
120 | |
---|
121 | $this->assertEquals(1, count($result->getExplainOther())); |
---|
122 | $doc = $result->getExplainOther()->getDocument('IW-02'); |
---|
123 | $this->assertEquals(0.6, $doc->getValue()); |
---|
124 | $this->assertEquals(true, $doc->getMatch()); |
---|
125 | $this->assertEquals('fieldWeight(text:ipod in 6), product of:', $doc->getDescription()); |
---|
126 | $this->assertEquals( |
---|
127 | array(new Solarium_Result_Select_Debug_Detail(true, 0.7, 'tf(termFreq(text:ipod)=1)')), |
---|
128 | $doc->getDetails() |
---|
129 | ); |
---|
130 | |
---|
131 | $timing = $result->getTiming(); |
---|
132 | $this->assertEquals(36, $timing->getTime()); |
---|
133 | $this->assertEquals(2, count($timing->getPhases())); |
---|
134 | $phase = $timing->getPhase('process'); |
---|
135 | $this->assertEquals(8, $phase->getTime()); |
---|
136 | $this->assertEquals(2, count($phase->getTimings())); |
---|
137 | $this->assertEquals(5, $phase->getTiming('org.apache.solr.handler.component.QueryComponent')); |
---|
138 | $this->assertEquals(3, $phase->getTiming('org.apache.solr.handler.component.MoreLikeThisComponent')); |
---|
139 | } |
---|
140 | |
---|
141 | public function testParseNoExplainData() |
---|
142 | { |
---|
143 | $data = array( |
---|
144 | 'debug' => array( |
---|
145 | 'querystring' => 'dummy-qs', |
---|
146 | 'parsedquery' => 'dummy-pq', |
---|
147 | 'QParser' => 'dummy-qp', |
---|
148 | 'otherQuery' => 'dummy-oq', |
---|
149 | ) |
---|
150 | ); |
---|
151 | |
---|
152 | $result = $this->_parser->parse(null, null, $data); |
---|
153 | $this->assertEquals('dummy-qs', $result->getQueryString()); |
---|
154 | $this->assertEquals('dummy-pq', $result->getParsedQuery()); |
---|
155 | $this->assertEquals('dummy-qp', $result->getQueryParser()); |
---|
156 | $this->assertEquals('dummy-oq', $result->getOtherQuery()); |
---|
157 | |
---|
158 | $this->assertEquals(0, count($result->getExplain())); |
---|
159 | $this->assertEquals(0, count($result->getExplainOther())); |
---|
160 | } |
---|
161 | |
---|
162 | public function testParseNoData() |
---|
163 | { |
---|
164 | $result = $this->_parser->parse(null, null, array()); |
---|
165 | $this->assertEquals(null, $result); |
---|
166 | } |
---|
167 | |
---|
168 | } |
---|