equal
deleted
inserted
replaced
40 ] |
40 ] |
41 ] |
41 ] |
42 ] |
42 ] |
43 ] |
43 ] |
44 ]; |
44 ]; |
|
45 |
|
46 $this->ES_QUERY_MINMAX = [ |
|
47 'index' => 'corpus', |
|
48 'body' => [ |
|
49 "size" => 0, |
|
50 "query" => [ "match_all" => (object) null ], |
|
51 "aggs" => [ |
|
52 "datestats" => [ |
|
53 "nested"=> [ |
|
54 "path" => "creation_years" |
|
55 ], |
|
56 "aggs" => [ |
|
57 "minyear" => [ |
|
58 "min" => [ "field"=> "creation_years.year" ] |
|
59 ], |
|
60 "maxyear" => [ |
|
61 "max" => [ "field"=> "creation_years.year" ] |
|
62 ] |
|
63 ] |
|
64 ] |
|
65 ] |
|
66 ] |
|
67 ]; |
45 } |
68 } |
46 |
69 |
47 public function tearDown() { |
70 public function tearDown() { |
48 m::close(); |
71 m::close(); |
49 parent::tearDown(); |
72 parent::tearDown(); |
145 "1986" => 14, |
168 "1986" => 14, |
146 "1996" => 36 |
169 "1996" => 36 |
147 ]]); |
170 ]]); |
148 } |
171 } |
149 |
172 |
|
173 |
|
174 public function testMinMaxQuery() { |
|
175 |
|
176 Es::shouldReceive('search') |
|
177 ->once() |
|
178 ->with($this->ES_QUERY_MINMAX) |
|
179 ->andReturn(json_decode('{ |
|
180 "took" : 708, |
|
181 "timed_out" : false, |
|
182 "_shards" : { |
|
183 "total" : 1, |
|
184 "successful" : 1, |
|
185 "failed" : 0 |
|
186 }, |
|
187 "hits" : { |
|
188 "total" : 0, |
|
189 "max_score" : 0.0, |
|
190 "hits" : [ ] |
|
191 }, |
|
192 "aggregations" : { |
|
193 "datestats" : { |
|
194 "doc_count" : 0, |
|
195 "maxyear" : { |
|
196 "value" : null |
|
197 }, |
|
198 "minyear" : { |
|
199 "value" : null |
|
200 } |
|
201 } |
|
202 } |
|
203 }', true)); |
|
204 $this->get('/api/v1/stats/dateminmax/')->assertTrue($this->response->isOk(), $this->response->content()); |
|
205 $this->seeJsonEquals(["dateminmax" => [0, 0]]); |
|
206 } |
|
207 |
|
208 public function testMinMaxResult() { |
|
209 |
|
210 Es::shouldReceive('search') |
|
211 ->once() |
|
212 ->with($this->ES_QUERY_MINMAX) |
|
213 ->andReturn(json_decode('{ |
|
214 "took" : 708, |
|
215 "timed_out" : false, |
|
216 "_shards" : { |
|
217 "total" : 1, |
|
218 "successful" : 1, |
|
219 "failed" : 0 |
|
220 }, |
|
221 "hits" : { |
|
222 "total" : 3375, |
|
223 "max_score" : 0.0, |
|
224 "hits" : [ ] |
|
225 }, |
|
226 "aggregations" : { |
|
227 "datestats" : { |
|
228 "doc_count" : 3727, |
|
229 "maxyear" : { |
|
230 "value" : 2015.0 |
|
231 }, |
|
232 "minyear" : { |
|
233 "value" : 1948.0 |
|
234 } |
|
235 } |
|
236 } |
|
237 }', true)); |
|
238 $this->get('/api/v1/stats/dateminmax/')->assertTrue($this->response->isOk(), $this->response->content()); |
|
239 $this->seeJsonEquals(["dateminmax" => [ 1948, 2015 ]]); |
|
240 } |
|
241 |
150 } |
242 } |