1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SilverStripe\Elastica\ElasticSearcher; |
4
|
|
|
use SilverStripe\Elastica\QueryGenerator; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Test the functionality of the Searchable extension |
8
|
|
|
* @package elastica |
9
|
|
|
*/ |
10
|
|
|
class AggregationUnitTest extends ElasticsearchBaseTest { |
11
|
|
|
public static $fixture_file = 'elastica/tests/lotsOfPhotos.yml'; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
public function testAllFieldsQuery() { |
15
|
|
|
//Use a text search against all fields |
16
|
|
|
$resultList = $this->search('New Zealand', null); |
|
|
|
|
17
|
|
|
$this->assertEquals(10, $resultList->count()); |
18
|
|
|
|
19
|
|
|
// check the query formation |
20
|
|
|
$query = $resultList->getQuery()->toArray(); |
21
|
|
|
$this->assertEquals(0, $query['from']); |
22
|
|
|
$this->assertEquals(10, $query['size']); |
23
|
|
|
|
24
|
|
|
$sort = array('TakenAt' => 'desc'); |
25
|
|
|
|
26
|
|
|
$this->assertFalse(isset($query['sort']), 'Sort should not be set as text is being used'); |
27
|
|
|
|
28
|
|
|
$expected = array('query' => 'New Zealand', 'lenient' => 1); |
29
|
|
|
$this->assertEquals($expected, $query['query']['query_string']); |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
// check the aggregate results |
33
|
|
|
$aggregations = $resultList->getAggregations(); |
34
|
|
|
|
35
|
|
|
//Asserting name of aggregate as ISO |
36
|
|
|
$agg = $aggregations[0]; |
37
|
|
|
$this->assertEquals("ISO", $agg->Name); |
38
|
|
|
$buckets = $agg->Buckets->toArray(); |
39
|
|
|
|
40
|
|
|
//Asserting aggregate of ISO, 64 has count 5 |
41
|
|
|
$this->assertEquals("64", $buckets[0]->Key); |
42
|
|
|
$this->assertEquals(5, $buckets[0]->DocumentCount); |
43
|
|
|
|
44
|
|
|
//Asserting aggregate of ISO, 100 has count 11 |
45
|
|
|
$this->assertEquals("100", $buckets[1]->Key); |
46
|
|
|
$this->assertEquals(11, $buckets[1]->DocumentCount); |
47
|
|
|
|
48
|
|
|
//Asserting aggregate of ISO, 200 has count 12 |
49
|
|
|
$this->assertEquals("200", $buckets[2]->Key); |
50
|
|
|
$this->assertEquals(12, $buckets[2]->DocumentCount); |
51
|
|
|
|
52
|
|
|
//Asserting aggregate of ISO, 400 has count 13 |
53
|
|
|
$this->assertEquals("400", $buckets[3]->Key); |
54
|
|
|
$this->assertEquals(13, $buckets[3]->DocumentCount); |
55
|
|
|
|
56
|
|
|
//Asserting aggregate of ISO, 800 has count 15 |
57
|
|
|
$this->assertEquals("800", $buckets[4]->Key); |
58
|
|
|
$this->assertEquals(15, $buckets[4]->DocumentCount); |
59
|
|
|
|
60
|
|
|
//Asserting aggregate of ISO, 1600 has count 13 |
61
|
|
|
$this->assertEquals("1600", $buckets[5]->Key); |
62
|
|
|
$this->assertEquals(13, $buckets[5]->DocumentCount); |
63
|
|
|
|
64
|
|
|
//Asserting aggregate of ISO, 2000 has count 11 |
65
|
|
|
$this->assertEquals("2000", $buckets[6]->Key); |
66
|
|
|
$this->assertEquals(11, $buckets[6]->DocumentCount); |
67
|
|
|
|
68
|
|
|
//Asserting aggregate of ISO, 3200 has count 19 |
69
|
|
|
$this->assertEquals("3200", $buckets[7]->Key); |
70
|
|
|
$this->assertEquals(19, $buckets[7]->DocumentCount); |
71
|
|
|
|
72
|
|
|
//Asserting name of aggregate as Focal Length |
73
|
|
|
$agg = $aggregations[1]; |
74
|
|
|
$this->assertEquals("Focal Length", $agg->Name); |
75
|
|
|
$buckets = $agg->Buckets->toArray(); |
76
|
|
|
|
77
|
|
|
//Asserting aggregate of Focal Length, 24 has count 12 |
78
|
|
|
$this->assertEquals("24", $buckets[0]->Key); |
79
|
|
|
$this->assertEquals(12, $buckets[0]->DocumentCount); |
80
|
|
|
|
81
|
|
|
//Asserting aggregate of Focal Length, 50 has count 11 |
82
|
|
|
$this->assertEquals("50", $buckets[1]->Key); |
83
|
|
|
$this->assertEquals(11, $buckets[1]->DocumentCount); |
84
|
|
|
|
85
|
|
|
//Asserting aggregate of Focal Length, 80 has count 11 |
86
|
|
|
$this->assertEquals("80", $buckets[2]->Key); |
87
|
|
|
$this->assertEquals(11, $buckets[2]->DocumentCount); |
88
|
|
|
|
89
|
|
|
//Asserting aggregate of Focal Length, 90 has count 20 |
90
|
|
|
$this->assertEquals("90", $buckets[3]->Key); |
91
|
|
|
$this->assertEquals(20, $buckets[3]->DocumentCount); |
92
|
|
|
|
93
|
|
|
//Asserting aggregate of Focal Length, 120 has count 11 |
94
|
|
|
$this->assertEquals("120", $buckets[4]->Key); |
95
|
|
|
$this->assertEquals(11, $buckets[4]->DocumentCount); |
96
|
|
|
|
97
|
|
|
//Asserting aggregate of Focal Length, 150 has count 17 |
98
|
|
|
$this->assertEquals("150", $buckets[5]->Key); |
99
|
|
|
$this->assertEquals(17, $buckets[5]->DocumentCount); |
100
|
|
|
|
101
|
|
|
//Asserting aggregate of Focal Length, 200 has count 17 |
102
|
|
|
$this->assertEquals("200", $buckets[6]->Key); |
103
|
|
|
$this->assertEquals(17, $buckets[6]->DocumentCount); |
104
|
|
|
|
105
|
|
|
//Asserting name of aggregate as Shutter Speed |
106
|
|
|
$agg = $aggregations[2]; |
107
|
|
|
$this->assertEquals("Shutter Speed", $agg->Name); |
108
|
|
|
$buckets = $agg->Buckets->toArray(); |
109
|
|
|
|
110
|
|
|
//Asserting aggregate of Shutter Speed, 2/250 has count 17 |
111
|
|
|
$this->assertEquals("2/250", $buckets[0]->Key); |
112
|
|
|
$this->assertEquals(17, $buckets[0]->DocumentCount); |
113
|
|
|
|
114
|
|
|
//Asserting aggregate of Shutter Speed, 1/100 has count 15 |
115
|
|
|
$this->assertEquals("1/100", $buckets[1]->Key); |
116
|
|
|
$this->assertEquals(15, $buckets[1]->DocumentCount); |
117
|
|
|
|
118
|
|
|
//Asserting aggregate of Shutter Speed, 1/30 has count 17 |
119
|
|
|
$this->assertEquals("1/30", $buckets[2]->Key); |
120
|
|
|
$this->assertEquals(17, $buckets[2]->DocumentCount); |
121
|
|
|
|
122
|
|
|
//Asserting aggregate of Shutter Speed, 1/15 has count 9 |
123
|
|
|
$this->assertEquals("1/15", $buckets[3]->Key); |
124
|
|
|
$this->assertEquals(9, $buckets[3]->DocumentCount); |
125
|
|
|
|
126
|
|
|
//Asserting aggregate of Shutter Speed, 1/2 has count 18 |
127
|
|
|
$this->assertEquals("1/2", $buckets[4]->Key); |
128
|
|
|
$this->assertEquals(18, $buckets[4]->DocumentCount); |
129
|
|
|
|
130
|
|
|
//Asserting aggregate of Shutter Speed, 1 has count 1 |
131
|
|
|
$this->assertEquals("1", $buckets[5]->Key); |
132
|
|
|
$this->assertEquals(1, $buckets[5]->DocumentCount); |
133
|
|
|
|
134
|
|
|
//Asserting aggregate of Shutter Speed, 2 has count 10 |
135
|
|
|
$this->assertEquals("2", $buckets[6]->Key); |
136
|
|
|
$this->assertEquals(10, $buckets[6]->DocumentCount); |
137
|
|
|
|
138
|
|
|
//Asserting aggregate of Shutter Speed, 6 has count 12 |
139
|
|
|
$this->assertEquals("6", $buckets[7]->Key); |
140
|
|
|
$this->assertEquals(12, $buckets[7]->DocumentCount); |
141
|
|
|
|
142
|
|
|
//Asserting name of aggregate as Aperture |
143
|
|
|
$agg = $aggregations[3]; |
144
|
|
|
$this->assertEquals("Aperture", $agg->Name); |
145
|
|
|
$buckets = $agg->Buckets->toArray(); |
146
|
|
|
|
147
|
|
|
//Asserting aggregate of Aperture, 2.8 has count 20 |
148
|
|
|
$this->assertEquals("2.8", $buckets[0]->Key); |
149
|
|
|
$this->assertEquals(20, $buckets[0]->DocumentCount); |
150
|
|
|
|
151
|
|
|
//Asserting aggregate of Aperture, 5.6 has count 23 |
152
|
|
|
$this->assertEquals("5.6", $buckets[1]->Key); |
153
|
|
|
$this->assertEquals(23, $buckets[1]->DocumentCount); |
154
|
|
|
|
155
|
|
|
//Asserting aggregate of Aperture, 11 has count 17 |
156
|
|
|
$this->assertEquals("11", $buckets[2]->Key); |
157
|
|
|
$this->assertEquals(17, $buckets[2]->DocumentCount); |
158
|
|
|
|
159
|
|
|
//Asserting aggregate of Aperture, 16 has count 16 |
160
|
|
|
$this->assertEquals("16", $buckets[3]->Key); |
161
|
|
|
$this->assertEquals(16, $buckets[3]->DocumentCount); |
162
|
|
|
|
163
|
|
|
//Asserting aggregate of Aperture, 22 has count 23 |
164
|
|
|
$this->assertEquals("22", $buckets[4]->Key); |
165
|
|
|
$this->assertEquals(23, $buckets[4]->DocumentCount); |
166
|
|
|
|
167
|
|
|
//Asserting name of aggregate as Aspect |
168
|
|
|
$agg = $aggregations[4]; |
169
|
|
|
$this->assertEquals("Aspect", $agg->Name); |
170
|
|
|
$buckets = $agg->Buckets->toArray(); |
171
|
|
|
|
172
|
|
|
//Asserting aggregate of Aspect, Panoramic has count 9 |
173
|
|
|
$this->assertEquals("Panoramic", $buckets[0]->Key); |
174
|
|
|
$this->assertEquals(9, $buckets[0]->DocumentCount); |
175
|
|
|
|
176
|
|
|
//Asserting aggregate of Aspect, Horizontal has count 31 |
177
|
|
|
$this->assertEquals("Horizontal", $buckets[1]->Key); |
178
|
|
|
$this->assertEquals(31, $buckets[1]->DocumentCount); |
179
|
|
|
|
180
|
|
|
//Asserting aggregate of Aspect, Square has count 16 |
181
|
|
|
$this->assertEquals("Square", $buckets[2]->Key); |
182
|
|
|
$this->assertEquals(16, $buckets[2]->DocumentCount); |
183
|
|
|
|
184
|
|
|
//Asserting aggregate of Aspect, Vertical has count 38 |
185
|
|
|
$this->assertEquals("Vertical", $buckets[3]->Key); |
186
|
|
|
$this->assertEquals(38, $buckets[3]->DocumentCount); |
187
|
|
|
|
188
|
|
|
//Asserting aggregate of Aspect, Tallest has count 5 |
189
|
|
|
$this->assertEquals("Tallest", $buckets[4]->Key); |
190
|
|
|
$this->assertEquals(5, $buckets[4]->DocumentCount); |
191
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
public function testAllFieldsEmptyQuery() { |
196
|
|
|
//Use a text search against all fields |
197
|
|
|
$resultList = $this->search('', null); |
|
|
|
|
198
|
|
|
$this->assertEquals(10, $resultList->count()); |
199
|
|
|
|
200
|
|
|
//check query |
201
|
|
|
$query = $resultList->getQuery()->toArray(); |
202
|
|
|
$this->assertEquals(0, $query['from']); |
203
|
|
|
$this->assertEquals(10, $query['size']); |
204
|
|
|
|
205
|
|
|
$sort = array('TakenAt' => 'desc'); |
206
|
|
|
$this->assertEquals($sort, $query['sort']); |
207
|
|
|
$this->assertFalse(isset($query['query'])); |
208
|
|
|
|
209
|
|
|
$aggs = array(); |
210
|
|
|
$aggs['Aperture'] = array(); |
211
|
|
|
$aggs['ShutterSpeed'] = array(); |
212
|
|
|
$aggs['FocalLength35mm'] = array(); |
213
|
|
|
$aggs['ISO'] = array(); |
214
|
|
|
$aggs['Aspect'] = array(); |
215
|
|
|
|
216
|
|
|
//check aggregations |
217
|
|
|
$aggregations = $resultList->getAggregations(); |
218
|
|
|
//Asserting name of aggregate as ISO |
219
|
|
|
$agg = $aggregations[0]; |
220
|
|
|
$this->assertEquals("ISO", $agg->Name); |
221
|
|
|
$buckets = $agg->Buckets->toArray(); |
222
|
|
|
$bucketSum = 0; |
223
|
|
|
|
224
|
|
|
//Asserting aggregate of ISO, 64 has count 5 |
225
|
|
|
$this->assertEquals("64", $buckets[0]->Key); |
226
|
|
|
$this->assertEquals(5, $buckets[0]->DocumentCount); |
227
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
228
|
|
|
|
229
|
|
|
//Asserting aggregate of ISO, 100 has count 11 |
230
|
|
|
$this->assertEquals("100", $buckets[1]->Key); |
231
|
|
|
$this->assertEquals(11, $buckets[1]->DocumentCount); |
232
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
233
|
|
|
|
234
|
|
|
//Asserting aggregate of ISO, 200 has count 12 |
235
|
|
|
$this->assertEquals("200", $buckets[2]->Key); |
236
|
|
|
$this->assertEquals(12, $buckets[2]->DocumentCount); |
237
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
238
|
|
|
|
239
|
|
|
//Asserting aggregate of ISO, 400 has count 13 |
240
|
|
|
$this->assertEquals("400", $buckets[3]->Key); |
241
|
|
|
$this->assertEquals(13, $buckets[3]->DocumentCount); |
242
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
243
|
|
|
|
244
|
|
|
//Asserting aggregate of ISO, 800 has count 16 |
245
|
|
|
$this->assertEquals("800", $buckets[4]->Key); |
246
|
|
|
$this->assertEquals(16, $buckets[4]->DocumentCount); |
247
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
248
|
|
|
|
249
|
|
|
//Asserting aggregate of ISO, 1600 has count 13 |
250
|
|
|
$this->assertEquals("1600", $buckets[5]->Key); |
251
|
|
|
$this->assertEquals(13, $buckets[5]->DocumentCount); |
252
|
|
|
$bucketSum += $buckets[5]->DocumentCount; |
253
|
|
|
|
254
|
|
|
//Asserting aggregate of ISO, 2000 has count 11 |
255
|
|
|
$this->assertEquals("2000", $buckets[6]->Key); |
256
|
|
|
$this->assertEquals(11, $buckets[6]->DocumentCount); |
257
|
|
|
$bucketSum += $buckets[6]->DocumentCount; |
258
|
|
|
|
259
|
|
|
//Asserting aggregate of ISO, 3200 has count 19 |
260
|
|
|
$this->assertEquals("3200", $buckets[7]->Key); |
261
|
|
|
$this->assertEquals(19, $buckets[7]->DocumentCount); |
262
|
|
|
$bucketSum += $buckets[7]->DocumentCount; |
263
|
|
|
$this->assertEquals(100, $bucketSum); |
264
|
|
|
|
265
|
|
|
//Asserting name of aggregate as Focal Length |
266
|
|
|
$agg = $aggregations[1]; |
267
|
|
|
$this->assertEquals("Focal Length", $agg->Name); |
268
|
|
|
$buckets = $agg->Buckets->toArray(); |
269
|
|
|
$bucketSum = 0; |
270
|
|
|
|
271
|
|
|
//Asserting aggregate of Focal Length, 24 has count 12 |
272
|
|
|
$this->assertEquals("24", $buckets[0]->Key); |
273
|
|
|
$this->assertEquals(12, $buckets[0]->DocumentCount); |
274
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
275
|
|
|
|
276
|
|
|
//Asserting aggregate of Focal Length, 50 has count 11 |
277
|
|
|
$this->assertEquals("50", $buckets[1]->Key); |
278
|
|
|
$this->assertEquals(11, $buckets[1]->DocumentCount); |
279
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
280
|
|
|
|
281
|
|
|
//Asserting aggregate of Focal Length, 80 has count 11 |
282
|
|
|
$this->assertEquals("80", $buckets[2]->Key); |
283
|
|
|
$this->assertEquals(11, $buckets[2]->DocumentCount); |
284
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
285
|
|
|
|
286
|
|
|
//Asserting aggregate of Focal Length, 90 has count 20 |
287
|
|
|
$this->assertEquals("90", $buckets[3]->Key); |
288
|
|
|
$this->assertEquals(20, $buckets[3]->DocumentCount); |
289
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
290
|
|
|
|
291
|
|
|
//Asserting aggregate of Focal Length, 120 has count 12 |
292
|
|
|
$this->assertEquals("120", $buckets[4]->Key); |
293
|
|
|
$this->assertEquals(12, $buckets[4]->DocumentCount); |
294
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
295
|
|
|
|
296
|
|
|
//Asserting aggregate of Focal Length, 150 has count 17 |
297
|
|
|
$this->assertEquals("150", $buckets[5]->Key); |
298
|
|
|
$this->assertEquals(17, $buckets[5]->DocumentCount); |
299
|
|
|
$bucketSum += $buckets[5]->DocumentCount; |
300
|
|
|
|
301
|
|
|
//Asserting aggregate of Focal Length, 200 has count 17 |
302
|
|
|
$this->assertEquals("200", $buckets[6]->Key); |
303
|
|
|
$this->assertEquals(17, $buckets[6]->DocumentCount); |
304
|
|
|
$bucketSum += $buckets[6]->DocumentCount; |
305
|
|
|
$this->assertEquals(100, $bucketSum); |
306
|
|
|
|
307
|
|
|
//Asserting name of aggregate as Shutter Speed |
308
|
|
|
$agg = $aggregations[2]; |
309
|
|
|
$this->assertEquals("Shutter Speed", $agg->Name); |
310
|
|
|
$buckets = $agg->Buckets->toArray(); |
311
|
|
|
$bucketSum = 0; |
312
|
|
|
|
313
|
|
|
//Asserting aggregate of Shutter Speed, 2/250 has count 17 |
314
|
|
|
$this->assertEquals("2/250", $buckets[0]->Key); |
315
|
|
|
$this->assertEquals(17, $buckets[0]->DocumentCount); |
316
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
317
|
|
|
|
318
|
|
|
//Asserting aggregate of Shutter Speed, 1/100 has count 15 |
319
|
|
|
$this->assertEquals("1/100", $buckets[1]->Key); |
320
|
|
|
$this->assertEquals(15, $buckets[1]->DocumentCount); |
321
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
322
|
|
|
|
323
|
|
|
//Asserting aggregate of Shutter Speed, 1/30 has count 17 |
324
|
|
|
$this->assertEquals("1/30", $buckets[2]->Key); |
325
|
|
|
$this->assertEquals(17, $buckets[2]->DocumentCount); |
326
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
327
|
|
|
|
328
|
|
|
//Asserting aggregate of Shutter Speed, 1/15 has count 10 |
329
|
|
|
$this->assertEquals("1/15", $buckets[3]->Key); |
330
|
|
|
$this->assertEquals(10, $buckets[3]->DocumentCount); |
331
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
332
|
|
|
|
333
|
|
|
//Asserting aggregate of Shutter Speed, 1/2 has count 18 |
334
|
|
|
$this->assertEquals("1/2", $buckets[4]->Key); |
335
|
|
|
$this->assertEquals(18, $buckets[4]->DocumentCount); |
336
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
337
|
|
|
|
338
|
|
|
//Asserting aggregate of Shutter Speed, 1 has count 1 |
339
|
|
|
$this->assertEquals("1", $buckets[5]->Key); |
340
|
|
|
$this->assertEquals(1, $buckets[5]->DocumentCount); |
341
|
|
|
|
342
|
|
|
//Asserting aggregate of Shutter Speed, 2 has count 10 |
343
|
|
|
$this->assertEquals("2", $buckets[6]->Key); |
344
|
|
|
$this->assertEquals(10, $buckets[6]->DocumentCount); |
345
|
|
|
|
346
|
|
|
//Asserting aggregate of Shutter Speed, 6 has count 12 |
347
|
|
|
$this->assertEquals("6", $buckets[7]->Key); |
348
|
|
|
$this->assertEquals(12, $buckets[7]->DocumentCount); |
349
|
|
|
|
350
|
|
|
//Asserting name of aggregate as Aperture |
351
|
|
|
$agg = $aggregations[3]; |
352
|
|
|
$this->assertEquals("Aperture", $agg->Name); |
353
|
|
|
$buckets = $agg->Buckets->toArray(); |
354
|
|
|
$bucketSum = 0; |
355
|
|
|
|
356
|
|
|
//Asserting aggregate of Aperture, 2.8 has count 21 |
357
|
|
|
$this->assertEquals("2.8", $buckets[0]->Key); |
358
|
|
|
$this->assertEquals(21, $buckets[0]->DocumentCount); |
359
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
360
|
|
|
|
361
|
|
|
//Asserting aggregate of Aperture, 5.6 has count 23 |
362
|
|
|
$this->assertEquals("5.6", $buckets[1]->Key); |
363
|
|
|
$this->assertEquals(23, $buckets[1]->DocumentCount); |
364
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
365
|
|
|
|
366
|
|
|
//Asserting aggregate of Aperture, 11 has count 17 |
367
|
|
|
$this->assertEquals("11", $buckets[2]->Key); |
368
|
|
|
$this->assertEquals(17, $buckets[2]->DocumentCount); |
369
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
370
|
|
|
|
371
|
|
|
//Asserting aggregate of Aperture, 16 has count 16 |
372
|
|
|
$this->assertEquals("16", $buckets[3]->Key); |
373
|
|
|
$this->assertEquals(16, $buckets[3]->DocumentCount); |
374
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
375
|
|
|
|
376
|
|
|
//Asserting aggregate of Aperture, 22 has count 23 |
377
|
|
|
$this->assertEquals("22", $buckets[4]->Key); |
378
|
|
|
$this->assertEquals(23, $buckets[4]->DocumentCount); |
379
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
380
|
|
|
$this->assertEquals(100, $bucketSum); |
381
|
|
|
|
382
|
|
|
//Asserting name of aggregate as Aspect |
383
|
|
|
$agg = $aggregations[4]; |
384
|
|
|
$this->assertEquals("Aspect", $agg->Name); |
385
|
|
|
$buckets = $agg->Buckets->toArray(); |
386
|
|
|
$bucketSum = 0; |
387
|
|
|
|
388
|
|
|
//Asserting aggregate of Aspect, Panoramic has count 9 |
389
|
|
|
$this->assertEquals("Panoramic", $buckets[0]->Key); |
390
|
|
|
$this->assertEquals(9, $buckets[0]->DocumentCount); |
391
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
392
|
|
|
|
393
|
|
|
//Asserting aggregate of Aspect, Horizontal has count 31 |
394
|
|
|
$this->assertEquals("Horizontal", $buckets[1]->Key); |
395
|
|
|
$this->assertEquals(31, $buckets[1]->DocumentCount); |
396
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
397
|
|
|
|
398
|
|
|
//Asserting aggregate of Aspect, Square has count 16 |
399
|
|
|
$this->assertEquals("Square", $buckets[2]->Key); |
400
|
|
|
$this->assertEquals(16, $buckets[2]->DocumentCount); |
401
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
402
|
|
|
|
403
|
|
|
//Asserting aggregate of Aspect, Vertical has count 39 |
404
|
|
|
$this->assertEquals("Vertical", $buckets[3]->Key); |
405
|
|
|
$this->assertEquals(39, $buckets[3]->DocumentCount); |
406
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
407
|
|
|
|
408
|
|
|
//Asserting aggregate of Aspect, Tallest has count 5 |
409
|
|
|
$this->assertEquals("Tallest", $buckets[4]->Key); |
410
|
|
|
$this->assertEquals(5, $buckets[4]->DocumentCount); |
411
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
412
|
|
|
$this->assertEquals(100, $bucketSum); |
413
|
|
|
|
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
|
417
|
|
|
/* |
418
|
|
|
Search for an empty query against the Title and Description fields |
419
|
|
|
*/ |
420
|
|
|
public function testAggregationWithEmptyQuery() { |
421
|
|
|
$resultList = $this->search(''); |
422
|
|
|
|
423
|
|
|
//assert there are actually some results |
424
|
|
|
$this->assertGreaterThan(0,$resultList->getTotalItems()); |
425
|
|
|
$aggregations = $resultList->getAggregations()->toArray(); |
426
|
|
|
|
427
|
|
|
/* |
428
|
|
|
For all of the aggregates, all results are returned due to empty query string, so the number |
429
|
|
|
of aggregates should always add up to 100. Check some values at the database level for |
430
|
|
|
further confirmation also |
431
|
|
|
FIXME - finish DB checks |
432
|
|
|
*/ |
433
|
|
|
|
434
|
|
|
//Asserting name of aggregate as ISO |
435
|
|
|
$agg = $aggregations[0]; |
436
|
|
|
$this->assertEquals("ISO", $agg->Name); |
437
|
|
|
$buckets = $agg->Buckets->toArray(); |
438
|
|
|
$bucketSum = 0; |
439
|
|
|
|
440
|
|
|
//Asserting aggregate of ISO, 64 has count 5 |
441
|
|
|
$this->assertEquals("64", $buckets[0]->Key); |
442
|
|
|
$this->assertEquals(5, $buckets[0]->DocumentCount); |
443
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('ISO',64)->count(),5); |
444
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
445
|
|
|
|
446
|
|
|
//Asserting aggregate of ISO, 100 has count 11 |
447
|
|
|
$this->assertEquals("100", $buckets[1]->Key); |
448
|
|
|
$this->assertEquals(11, $buckets[1]->DocumentCount); |
449
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('ISO',100)->count(),11); |
450
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
451
|
|
|
|
452
|
|
|
//Asserting aggregate of ISO, 200 has count 12 |
453
|
|
|
$this->assertEquals("200", $buckets[2]->Key); |
454
|
|
|
$this->assertEquals(12, $buckets[2]->DocumentCount); |
455
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('ISO',200)->count(),12); |
456
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
457
|
|
|
|
458
|
|
|
//Asserting aggregate of ISO, 400 has count 13 |
459
|
|
|
$this->assertEquals("400", $buckets[3]->Key); |
460
|
|
|
$this->assertEquals(13, $buckets[3]->DocumentCount); |
461
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('ISO',400)->count(),13); |
462
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
463
|
|
|
|
464
|
|
|
//Asserting aggregate of ISO, 800 has count 16 |
465
|
|
|
$this->assertEquals("800", $buckets[4]->Key); |
466
|
|
|
$this->assertEquals(16, $buckets[4]->DocumentCount); |
467
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('ISO',800)->count(),16); |
468
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
469
|
|
|
|
470
|
|
|
//Asserting aggregate of ISO, 1600 has count 13 |
471
|
|
|
$this->assertEquals("1600", $buckets[5]->Key); |
472
|
|
|
$this->assertEquals(13, $buckets[5]->DocumentCount); |
473
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('ISO',1600)->count(),13); |
474
|
|
|
$bucketSum += $buckets[5]->DocumentCount; |
475
|
|
|
|
476
|
|
|
//Asserting aggregate of ISO, 2000 has count 11 |
477
|
|
|
$this->assertEquals("2000", $buckets[6]->Key); |
478
|
|
|
$this->assertEquals(11, $buckets[6]->DocumentCount); |
479
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('ISO',2000)->count(),11); |
480
|
|
|
$bucketSum += $buckets[6]->DocumentCount; |
481
|
|
|
|
482
|
|
|
//Asserting aggregate of ISO, 3200 has count 19 |
483
|
|
|
$this->assertEquals("3200", $buckets[7]->Key); |
484
|
|
|
$this->assertEquals(19, $buckets[7]->DocumentCount); |
485
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('ISO',3200)->count(),19); |
486
|
|
|
$bucketSum += $buckets[7]->DocumentCount; |
487
|
|
|
$this->assertEquals(100, $bucketSum); |
488
|
|
|
|
489
|
|
|
//Asserting name of aggregate as Focal Length |
490
|
|
|
$agg = $aggregations[1]; |
491
|
|
|
$this->assertEquals("Focal Length", $agg->Name); |
492
|
|
|
$buckets = $agg->Buckets->toArray(); |
493
|
|
|
$bucketSum = 0; |
494
|
|
|
|
495
|
|
|
//Asserting aggregate of Focal Length, 24 has count 12 |
496
|
|
|
$this->assertEquals("24", $buckets[0]->Key); |
497
|
|
|
$this->assertEquals(12, $buckets[0]->DocumentCount); |
498
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',24)->count(),12); |
499
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
500
|
|
|
|
501
|
|
|
//Asserting aggregate of Focal Length, 50 has count 11 |
502
|
|
|
$this->assertEquals("50", $buckets[1]->Key); |
503
|
|
|
$this->assertEquals(11, $buckets[1]->DocumentCount); |
504
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',50)->count(),11); |
505
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
506
|
|
|
|
507
|
|
|
//Asserting aggregate of Focal Length, 80 has count 11 |
508
|
|
|
$this->assertEquals("80", $buckets[2]->Key); |
509
|
|
|
$this->assertEquals(11, $buckets[2]->DocumentCount); |
510
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',80)->count(),11); |
511
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
512
|
|
|
|
513
|
|
|
//Asserting aggregate of Focal Length, 90 has count 20 |
514
|
|
|
$this->assertEquals("90", $buckets[3]->Key); |
515
|
|
|
$this->assertEquals(20, $buckets[3]->DocumentCount); |
516
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',90)->count(),20); |
517
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
518
|
|
|
|
519
|
|
|
//Asserting aggregate of Focal Length, 120 has count 12 |
520
|
|
|
$this->assertEquals("120", $buckets[4]->Key); |
521
|
|
|
$this->assertEquals(12, $buckets[4]->DocumentCount); |
522
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',120)->count(),12); |
523
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
524
|
|
|
|
525
|
|
|
//Asserting aggregate of Focal Length, 150 has count 17 |
526
|
|
|
$this->assertEquals("150", $buckets[5]->Key); |
527
|
|
|
$this->assertEquals(17, $buckets[5]->DocumentCount); |
528
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',150)->count(),17); |
529
|
|
|
$bucketSum += $buckets[5]->DocumentCount; |
530
|
|
|
|
531
|
|
|
//Asserting aggregate of Focal Length, 200 has count 17 |
532
|
|
|
$this->assertEquals("200", $buckets[6]->Key); |
533
|
|
|
$this->assertEquals(17, $buckets[6]->DocumentCount); |
534
|
|
|
$this->assertEquals(FlickrPhotoTO::get()->filter('FocalLength35mm',200)->count(),17); |
535
|
|
|
$bucketSum += $buckets[6]->DocumentCount; |
536
|
|
|
$this->assertEquals(100, $bucketSum); |
537
|
|
|
|
538
|
|
|
//Asserting name of aggregate as Shutter Speed |
539
|
|
|
$agg = $aggregations[2]; |
540
|
|
|
$this->assertEquals("Shutter Speed", $agg->Name); |
541
|
|
|
$buckets = $agg->Buckets->toArray(); |
542
|
|
|
$bucketSum = 0; |
543
|
|
|
|
544
|
|
|
//Asserting aggregate of Shutter Speed, 2/250 has count 17 |
545
|
|
|
$this->assertEquals("2/250", $buckets[0]->Key); |
546
|
|
|
$this->assertEquals(17, $buckets[0]->DocumentCount); |
547
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
548
|
|
|
|
549
|
|
|
//Asserting aggregate of Shutter Speed, 1/100 has count 15 |
550
|
|
|
$this->assertEquals("1/100", $buckets[1]->Key); |
551
|
|
|
$this->assertEquals(15, $buckets[1]->DocumentCount); |
552
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
553
|
|
|
|
554
|
|
|
//Asserting aggregate of Shutter Speed, 1/30 has count 17 |
555
|
|
|
$this->assertEquals("1/30", $buckets[2]->Key); |
556
|
|
|
$this->assertEquals(17, $buckets[2]->DocumentCount); |
557
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
558
|
|
|
|
559
|
|
|
//Asserting aggregate of Shutter Speed, 1/15 has count 10 |
560
|
|
|
$this->assertEquals("1/15", $buckets[3]->Key); |
561
|
|
|
$this->assertEquals(10, $buckets[3]->DocumentCount); |
562
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
563
|
|
|
|
564
|
|
|
//Asserting aggregate of Shutter Speed, 1/2 has count 18 |
565
|
|
|
$this->assertEquals("1/2", $buckets[4]->Key); |
566
|
|
|
$this->assertEquals(18, $buckets[4]->DocumentCount); |
567
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
568
|
|
|
|
569
|
|
|
//Asserting aggregate of Shutter Speed, 1 has count 1 |
570
|
|
|
$this->assertEquals("1", $buckets[5]->Key); |
571
|
|
|
$this->assertEquals(1, $buckets[5]->DocumentCount); |
572
|
|
|
|
573
|
|
|
//Asserting aggregate of Shutter Speed, 2 has count 10 |
574
|
|
|
$this->assertEquals("2", $buckets[6]->Key); |
575
|
|
|
$this->assertEquals(10, $buckets[6]->DocumentCount); |
576
|
|
|
|
577
|
|
|
//Asserting aggregate of Shutter Speed, 6 has count 12 |
578
|
|
|
$this->assertEquals("6", $buckets[7]->Key); |
579
|
|
|
$this->assertEquals(12, $buckets[7]->DocumentCount); |
580
|
|
|
|
581
|
|
|
//Asserting name of aggregate as Aperture |
582
|
|
|
$agg = $aggregations[3]; |
583
|
|
|
$this->assertEquals("Aperture", $agg->Name); |
584
|
|
|
$buckets = $agg->Buckets->toArray(); |
585
|
|
|
$bucketSum = 0; |
586
|
|
|
|
587
|
|
|
//Asserting aggregate of Aperture, 2.8 has count 21 |
588
|
|
|
$this->assertEquals("2.8", $buckets[0]->Key); |
589
|
|
|
$this->assertEquals(21, $buckets[0]->DocumentCount); |
590
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
591
|
|
|
|
592
|
|
|
//Asserting aggregate of Aperture, 5.6 has count 23 |
593
|
|
|
$this->assertEquals("5.6", $buckets[1]->Key); |
594
|
|
|
$this->assertEquals(23, $buckets[1]->DocumentCount); |
595
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
596
|
|
|
|
597
|
|
|
//Asserting aggregate of Aperture, 11 has count 17 |
598
|
|
|
$this->assertEquals("11", $buckets[2]->Key); |
599
|
|
|
$this->assertEquals(17, $buckets[2]->DocumentCount); |
600
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
601
|
|
|
|
602
|
|
|
//Asserting aggregate of Aperture, 16 has count 16 |
603
|
|
|
$this->assertEquals("16", $buckets[3]->Key); |
604
|
|
|
$this->assertEquals(16, $buckets[3]->DocumentCount); |
605
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
606
|
|
|
|
607
|
|
|
//Asserting aggregate of Aperture, 22 has count 23 |
608
|
|
|
$this->assertEquals("22", $buckets[4]->Key); |
609
|
|
|
$this->assertEquals(23, $buckets[4]->DocumentCount); |
610
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
611
|
|
|
$this->assertEquals(100, $bucketSum); |
612
|
|
|
|
613
|
|
|
//Asserting name of aggregate as Aspect |
614
|
|
|
$agg = $aggregations[4]; |
615
|
|
|
$this->assertEquals("Aspect", $agg->Name); |
616
|
|
|
$buckets = $agg->Buckets->toArray(); |
617
|
|
|
$bucketSum = 0; |
618
|
|
|
|
619
|
|
|
//Asserting aggregate of Aspect, Panoramic has count 9 |
620
|
|
|
$this->assertEquals("Panoramic", $buckets[0]->Key); |
621
|
|
|
$this->assertEquals(9, $buckets[0]->DocumentCount); |
622
|
|
|
$bucketSum += $buckets[0]->DocumentCount; |
623
|
|
|
|
624
|
|
|
//Asserting aggregate of Aspect, Horizontal has count 31 |
625
|
|
|
$this->assertEquals("Horizontal", $buckets[1]->Key); |
626
|
|
|
$this->assertEquals(31, $buckets[1]->DocumentCount); |
627
|
|
|
$bucketSum += $buckets[1]->DocumentCount; |
628
|
|
|
|
629
|
|
|
//Asserting aggregate of Aspect, Square has count 16 |
630
|
|
|
$this->assertEquals("Square", $buckets[2]->Key); |
631
|
|
|
$this->assertEquals(16, $buckets[2]->DocumentCount); |
632
|
|
|
$bucketSum += $buckets[2]->DocumentCount; |
633
|
|
|
|
634
|
|
|
//Asserting aggregate of Aspect, Vertical has count 39 |
635
|
|
|
$this->assertEquals("Vertical", $buckets[3]->Key); |
636
|
|
|
$this->assertEquals(39, $buckets[3]->DocumentCount); |
637
|
|
|
$bucketSum += $buckets[3]->DocumentCount; |
638
|
|
|
|
639
|
|
|
//Asserting aggregate of Aspect, Tallest has count 5 |
640
|
|
|
$this->assertEquals("Tallest", $buckets[4]->Key); |
641
|
|
|
$this->assertEquals(5, $buckets[4]->DocumentCount); |
642
|
|
|
$bucketSum += $buckets[4]->DocumentCount; |
643
|
|
|
$this->assertEquals(100, $bucketSum); |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
|
647
|
|
|
/* |
648
|
|
|
Search for the query 'New Zealand' against the Title and Description fields |
649
|
|
|
*/ |
650
|
|
|
public function testAggregationWithQuery() { |
651
|
|
|
$resultList = $this->search('New Zealand'); |
652
|
|
|
$aggregations = $resultList->getAggregations()->toArray(); |
653
|
|
|
|
654
|
|
|
|
655
|
|
|
//Asserting name of aggregate as ISO |
656
|
|
|
$agg = $aggregations[0]; |
657
|
|
|
|
658
|
|
|
|
659
|
|
|
$this->assertEquals("ISO", $agg->Name); |
660
|
|
|
$buckets = $agg->Buckets->toArray(); |
661
|
|
|
|
662
|
|
|
//Asserting aggregate of ISO, 64 has count 5 |
663
|
|
|
$this->assertEquals("64", $buckets[0]->Key); |
664
|
|
|
$this->assertEquals(5, $buckets[0]->DocumentCount); |
665
|
|
|
|
666
|
|
|
//Asserting aggregate of ISO, 100 has count 11 |
667
|
|
|
$this->assertEquals("100", $buckets[1]->Key); |
668
|
|
|
$this->assertEquals(11, $buckets[1]->DocumentCount); |
669
|
|
|
|
670
|
|
|
//Asserting aggregate of ISO, 200 has count 12 |
671
|
|
|
$this->assertEquals("200", $buckets[2]->Key); |
672
|
|
|
$this->assertEquals(12, $buckets[2]->DocumentCount); |
673
|
|
|
|
674
|
|
|
//Asserting aggregate of ISO, 400 has count 13 |
675
|
|
|
$this->assertEquals("400", $buckets[3]->Key); |
676
|
|
|
$this->assertEquals(13, $buckets[3]->DocumentCount); |
677
|
|
|
|
678
|
|
|
//Asserting aggregate of ISO, 800 has count 16 |
679
|
|
|
$this->assertEquals("800", $buckets[4]->Key); |
680
|
|
|
$this->assertEquals(16, $buckets[4]->DocumentCount); |
681
|
|
|
|
682
|
|
|
//Asserting aggregate of ISO, 1600 has count 13 |
683
|
|
|
$this->assertEquals("1600", $buckets[5]->Key); |
684
|
|
|
$this->assertEquals(13, $buckets[5]->DocumentCount); |
685
|
|
|
|
686
|
|
|
//Asserting aggregate of ISO, 2000 has count 11 |
687
|
|
|
$this->assertEquals("2000", $buckets[6]->Key); |
688
|
|
|
$this->assertEquals(11, $buckets[6]->DocumentCount); |
689
|
|
|
|
690
|
|
|
//Asserting aggregate of ISO, 3200 has count 19 |
691
|
|
|
$this->assertEquals("3200", $buckets[7]->Key); |
692
|
|
|
$this->assertEquals(19, $buckets[7]->DocumentCount); |
693
|
|
|
|
694
|
|
|
//Asserting name of aggregate as Focal Length |
695
|
|
|
$agg = $aggregations[1]; |
696
|
|
|
$this->assertEquals("Focal Length", $agg->Name); |
697
|
|
|
$buckets = $agg->Buckets->toArray(); |
698
|
|
|
|
699
|
|
|
//Asserting aggregate of Focal Length, 24 has count 12 |
700
|
|
|
$this->assertEquals("24", $buckets[0]->Key); |
701
|
|
|
$this->assertEquals(12, $buckets[0]->DocumentCount); |
702
|
|
|
|
703
|
|
|
//Asserting aggregate of Focal Length, 50 has count 11 |
704
|
|
|
$this->assertEquals("50", $buckets[1]->Key); |
705
|
|
|
$this->assertEquals(11, $buckets[1]->DocumentCount); |
706
|
|
|
|
707
|
|
|
//Asserting aggregate of Focal Length, 80 has count 11 |
708
|
|
|
$this->assertEquals("80", $buckets[2]->Key); |
709
|
|
|
$this->assertEquals(11, $buckets[2]->DocumentCount); |
710
|
|
|
|
711
|
|
|
//Asserting aggregate of Focal Length, 90 has count 20 |
712
|
|
|
$this->assertEquals("90", $buckets[3]->Key); |
713
|
|
|
$this->assertEquals(20, $buckets[3]->DocumentCount); |
714
|
|
|
|
715
|
|
|
//Asserting aggregate of Focal Length, 120 has count 12 |
716
|
|
|
$this->assertEquals("120", $buckets[4]->Key); |
717
|
|
|
$this->assertEquals(12, $buckets[4]->DocumentCount); |
718
|
|
|
|
719
|
|
|
//Asserting aggregate of Focal Length, 150 has count 17 |
720
|
|
|
$this->assertEquals("150", $buckets[5]->Key); |
721
|
|
|
$this->assertEquals(17, $buckets[5]->DocumentCount); |
722
|
|
|
|
723
|
|
|
//Asserting aggregate of Focal Length, 200 has count 17 |
724
|
|
|
$this->assertEquals("200", $buckets[6]->Key); |
725
|
|
|
$this->assertEquals(17, $buckets[6]->DocumentCount); |
726
|
|
|
|
727
|
|
|
//Asserting name of aggregate as Shutter Speed |
728
|
|
|
$agg = $aggregations[2]; |
729
|
|
|
$this->assertEquals("Shutter Speed", $agg->Name); |
730
|
|
|
$buckets = $agg->Buckets->toArray(); |
731
|
|
|
|
732
|
|
|
//Asserting aggregate of Shutter Speed, 2/250 has count 17 |
733
|
|
|
$this->assertEquals("2/250", $buckets[0]->Key); |
734
|
|
|
$this->assertEquals(17, $buckets[0]->DocumentCount); |
735
|
|
|
|
736
|
|
|
//Asserting aggregate of Shutter Speed, 1/100 has count 15 |
737
|
|
|
$this->assertEquals("1/100", $buckets[1]->Key); |
738
|
|
|
$this->assertEquals(15, $buckets[1]->DocumentCount); |
739
|
|
|
|
740
|
|
|
//Asserting aggregate of Shutter Speed, 1/30 has count 17 |
741
|
|
|
$this->assertEquals("1/30", $buckets[2]->Key); |
742
|
|
|
$this->assertEquals(17, $buckets[2]->DocumentCount); |
743
|
|
|
|
744
|
|
|
//Asserting aggregate of Shutter Speed, 1/15 has count 10 |
745
|
|
|
$this->assertEquals("1/15", $buckets[3]->Key); |
746
|
|
|
$this->assertEquals(10, $buckets[3]->DocumentCount); |
747
|
|
|
|
748
|
|
|
//Asserting aggregate of Shutter Speed, 1/2 has count 18 |
749
|
|
|
$this->assertEquals("1/2", $buckets[4]->Key); |
750
|
|
|
$this->assertEquals(18, $buckets[4]->DocumentCount); |
751
|
|
|
|
752
|
|
|
//Asserting aggregate of Shutter Speed, 1 has count 1 |
753
|
|
|
$this->assertEquals("1", $buckets[5]->Key); |
754
|
|
|
$this->assertEquals(1, $buckets[5]->DocumentCount); |
755
|
|
|
|
756
|
|
|
//Asserting aggregate of Shutter Speed, 2 has count 10 |
757
|
|
|
$this->assertEquals("2", $buckets[6]->Key); |
758
|
|
|
$this->assertEquals(10, $buckets[6]->DocumentCount); |
759
|
|
|
|
760
|
|
|
//Asserting aggregate of Shutter Speed, 6 has count 12 |
761
|
|
|
$this->assertEquals("6", $buckets[7]->Key); |
762
|
|
|
$this->assertEquals(12, $buckets[7]->DocumentCount); |
763
|
|
|
|
764
|
|
|
//Asserting name of aggregate as Aperture |
765
|
|
|
$agg = $aggregations[3]; |
766
|
|
|
$this->assertEquals("Aperture", $agg->Name); |
767
|
|
|
$buckets = $agg->Buckets->toArray(); |
768
|
|
|
|
769
|
|
|
//Asserting aggregate of Aperture, 2.8 has count 21 |
770
|
|
|
$this->assertEquals("2.8", $buckets[0]->Key); |
771
|
|
|
$this->assertEquals(21, $buckets[0]->DocumentCount); |
772
|
|
|
|
773
|
|
|
//Asserting aggregate of Aperture, 5.6 has count 23 |
774
|
|
|
$this->assertEquals("5.6", $buckets[1]->Key); |
775
|
|
|
$this->assertEquals(23, $buckets[1]->DocumentCount); |
776
|
|
|
|
777
|
|
|
//Asserting aggregate of Aperture, 11 has count 17 |
778
|
|
|
$this->assertEquals("11", $buckets[2]->Key); |
779
|
|
|
$this->assertEquals(17, $buckets[2]->DocumentCount); |
780
|
|
|
|
781
|
|
|
//Asserting aggregate of Aperture, 16 has count 16 |
782
|
|
|
$this->assertEquals("16", $buckets[3]->Key); |
783
|
|
|
$this->assertEquals(16, $buckets[3]->DocumentCount); |
784
|
|
|
|
785
|
|
|
//Asserting aggregate of Aperture, 22 has count 23 |
786
|
|
|
$this->assertEquals("22", $buckets[4]->Key); |
787
|
|
|
$this->assertEquals(23, $buckets[4]->DocumentCount); |
788
|
|
|
|
789
|
|
|
//Asserting name of aggregate as Aspect |
790
|
|
|
$agg = $aggregations[4]; |
791
|
|
|
$this->assertEquals("Aspect", $agg->Name); |
792
|
|
|
$buckets = $agg->Buckets->toArray(); |
793
|
|
|
|
794
|
|
|
//Asserting aggregate of Aspect, Panoramic has count 9 |
795
|
|
|
$this->assertEquals("Panoramic", $buckets[0]->Key); |
796
|
|
|
$this->assertEquals(9, $buckets[0]->DocumentCount); |
797
|
|
|
|
798
|
|
|
//Asserting aggregate of Aspect, Horizontal has count 31 |
799
|
|
|
$this->assertEquals("Horizontal", $buckets[1]->Key); |
800
|
|
|
$this->assertEquals(31, $buckets[1]->DocumentCount); |
801
|
|
|
|
802
|
|
|
//Asserting aggregate of Aspect, Square has count 16 |
803
|
|
|
$this->assertEquals("Square", $buckets[2]->Key); |
804
|
|
|
$this->assertEquals(16, $buckets[2]->DocumentCount); |
805
|
|
|
|
806
|
|
|
//Asserting aggregate of Aspect, Vertical has count 39 |
807
|
|
|
$this->assertEquals("Vertical", $buckets[3]->Key); |
808
|
|
|
$this->assertEquals(39, $buckets[3]->DocumentCount); |
809
|
|
|
|
810
|
|
|
//Asserting aggregate of Aspect, Tallest has count 5 |
811
|
|
|
$this->assertEquals("Tallest", $buckets[4]->Key); |
812
|
|
|
$this->assertEquals(5, $buckets[4]->DocumentCount); |
813
|
|
|
} |
814
|
|
|
|
815
|
|
|
|
816
|
|
|
public function testOneAggregateSelected() { |
817
|
|
|
$fields = array('Title' => 1, 'Description' => 1); |
818
|
|
|
$resultList = $this->search('New Zealand', $fields); |
819
|
|
|
$originalAggregations = $resultList->getAggregations()->toArray(); |
820
|
|
|
|
821
|
|
|
$filters = array('ISO' => 3200); |
822
|
|
|
$resultListFiltered = $this->search('New Zealand', $fields,$filters); |
823
|
|
|
$filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
824
|
|
|
|
825
|
|
|
$this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
826
|
|
|
} |
827
|
|
|
|
828
|
|
|
|
829
|
|
|
public function testTwoAggregatesSelected() { |
830
|
|
|
$fields = array('Title' => 1, 'Description' => 1); |
831
|
|
|
$resultList = $this->search('New Zealand', $fields, array('ISO' => 400)); |
832
|
|
|
$originalAggregations = $resultList->getAggregations()->toArray(); |
833
|
|
|
|
834
|
|
|
$filters = array('ISO' => 400, 'Aspect' => 'Vertical' ); |
835
|
|
|
$resultListFiltered = $this->search('New Zealand', $fields,$filters); |
836
|
|
|
$filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
837
|
|
|
|
838
|
|
|
$this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
|
842
|
|
|
public function testThreeAggregatesSelected() { |
843
|
|
|
$ct = FlickrPhotoTO::get()->count(); |
|
|
|
|
844
|
|
|
|
845
|
|
|
$fields = array('Title' => 1, 'Description' => 1); |
846
|
|
|
$resultList = $this->search('New Zealand', $fields, array('ISO' => 400, |
847
|
|
|
'Aspect' => 'Vertical')); |
848
|
|
|
$originalAggregations = $resultList->getAggregations()->toArray(); |
849
|
|
|
|
850
|
|
|
$filters = array('ISO' => 400, 'Aspect' => 'Vertical', 'Aperture' => 5 ); |
851
|
|
|
$resultListFiltered = $this->search('New Zealand', $fields,$filters); |
852
|
|
|
$filteredAggregations = $resultListFiltered->getAggregations()->toArray(); |
853
|
|
|
|
854
|
|
|
$this->checkDrillingDownHasHappened($filteredAggregations, $originalAggregations); |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
|
858
|
|
|
/* |
859
|
|
|
Shutter speed is a special case as values are manipulated in order to maintain correct sort order |
860
|
|
|
*/ |
861
|
|
|
public function testAggregateShutterSpeed() { |
862
|
|
|
$fields = array('Title' => 1, 'Description' => 1); |
863
|
|
|
$resultList = $this->search('', $fields, array('ShutterSpeed' => '1/100')); |
864
|
|
|
$aggregations = $resultList->getAggregations()->toArray(); |
|
|
|
|
865
|
|
|
|
866
|
|
|
// 15 instances in the YML file |
867
|
|
|
$this->assertEquals(15, $resultList->getTotalItems()); |
868
|
|
|
|
869
|
|
|
// Shutter speed of 1 second is a special case, only 1 case |
870
|
|
|
$resultList = $this->search('Image taken from page 471', $fields, array('ShutterSpeed' => '1')); |
871
|
|
|
$this->assertEquals(1, $resultList->getTotalItems()); |
872
|
|
|
|
873
|
|
|
// test outlying vals and ensure they do not crash the code |
874
|
|
|
$resultList = $this->search('Image taken from page 471', $fields, array('ShutterSpeed' => '')); |
875
|
|
|
$this->assertEquals(0, $resultList->getTotalItems()); |
876
|
|
|
|
877
|
|
|
$resultList = $this->search('Image taken from page 471', $fields, array('ShutterSpeed' => '/')); |
878
|
|
|
$this->assertEquals(0, $resultList->getTotalItems()); |
879
|
|
|
|
880
|
|
|
$resultList = $this->search('Image taken from page 471', $fields, array('ShutterSpeed' => '2/')); |
881
|
|
|
$this->assertEquals(0, $resultList->getTotalItems()); |
882
|
|
|
|
883
|
|
|
$resultList = $this->search('Image taken from page 471', $fields, array('ShutterSpeed' => '/2')); |
884
|
|
|
$this->assertEquals(0, $resultList->getTotalItems()); |
885
|
|
|
} |
886
|
|
|
|
887
|
|
|
|
888
|
|
|
private function checkDrillingDownHasHappened($filteredAggregations, $originalAggregations) { |
889
|
|
|
$aggCtr = 0; |
890
|
|
|
|
891
|
|
|
foreach ($filteredAggregations as $filteredAgg) { |
892
|
|
|
$origAgg = $originalAggregations[$aggCtr]; |
893
|
|
|
$bucketCtr = 0; |
|
|
|
|
894
|
|
|
$origBuckets = $origAgg->Buckets->toArray(); |
895
|
|
|
$filteredBuckets = $filteredAgg->Buckets->toArray(); |
896
|
|
|
|
897
|
|
|
$origCounts = array(); |
898
|
|
|
$filteredCounts = array(); |
899
|
|
|
|
900
|
|
|
foreach ($origBuckets as $bucket) { |
901
|
|
|
$origCounts[$bucket->Key] = $bucket->DocumentCount; |
902
|
|
|
} |
903
|
|
|
|
904
|
|
|
foreach ($filteredBuckets as $bucket) { |
905
|
|
|
$filteredCounts[$bucket->Key] = $bucket->DocumentCount; |
906
|
|
|
} |
907
|
|
|
|
908
|
|
|
$akf = array_keys($filteredCounts); |
909
|
|
|
|
910
|
|
|
foreach ($akf as $aggregateKey) { |
911
|
|
|
$this->assertGreaterThanOrEqual( |
912
|
|
|
$filteredCounts[$aggregateKey], $origCounts[$aggregateKey] |
913
|
|
|
); |
914
|
|
|
} |
915
|
|
|
|
916
|
|
|
$aggCtr++; |
917
|
|
|
} |
918
|
|
|
} |
919
|
|
|
|
920
|
|
|
|
921
|
|
|
/* |
922
|
|
|
ResultList and ElasticSearcher both have accessors to the aggregates. Check they are the same |
923
|
|
|
*/ |
924
|
|
View Code Duplication |
public function testGetAggregations() { |
925
|
|
|
$es = new ElasticSearcher(); |
926
|
|
|
$es->setStart(0); |
927
|
|
|
$es->setPageLength(10); |
928
|
|
|
//$es->addFilter('IsInSiteTree', false); |
|
|
|
|
929
|
|
|
$es->setClasses('FlickrPhotoTO'); |
930
|
|
|
$es->setQueryResultManipulator('FlickrPhotoTOElasticaSearchHelper'); |
|
|
|
|
931
|
|
|
$resultList = $es->search('New Zealand'); |
932
|
|
|
$this->assertEquals($resultList->getAggregations(), $es->getAggregations()); |
933
|
|
|
} |
934
|
|
|
|
935
|
|
|
|
936
|
|
|
public function testAggregationNonExistentField() { |
937
|
|
|
$filters = array(); |
938
|
|
|
$es = new ElasticSearcher(); |
939
|
|
|
$es->setStart(0); |
940
|
|
|
$es->setPageLength(10); |
941
|
|
|
//$es->addFilter('IsInSiteTree', false); |
|
|
|
|
942
|
|
|
$es->setClasses('FlickrPhotoTO'); |
943
|
|
|
$es->setQueryResultManipulator('FlickrPhotoTOElasticaSearchHelper'); |
|
|
|
|
944
|
|
|
|
945
|
|
|
//Add filters |
946
|
|
|
foreach ($filters as $key => $value) { |
947
|
|
|
$es->addFilter($key,$value); |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
$es->showResultsForEmptySearch(); |
951
|
|
|
|
952
|
|
|
try { |
953
|
|
|
$resultList = $es->search('whatever', array('Wibble' => 2)); |
|
|
|
|
954
|
|
|
$this->fail('The field Wibble should cause this to error out with an exception'); |
955
|
|
|
} catch (Exception $e) { |
956
|
|
|
$this->assertEquals('Field Wibble does not exist', $e->getMessage()); |
957
|
|
|
} |
958
|
|
|
|
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* Test searching |
964
|
|
|
* http://stackoverflow.com/questions/28305250/elasticsearch-customize-score-for-synonyms-stemming |
965
|
|
|
*/ |
966
|
|
|
private function search($queryText,$fields = array('Title' => 1, 'Description' => 1), |
967
|
|
|
$filters = array()) { |
968
|
|
|
$es = new ElasticSearcher(); |
969
|
|
|
$es->setStart(0); |
970
|
|
|
$es->setPageLength(10); |
971
|
|
|
$es->setClasses('FlickrPhotoTO'); |
972
|
|
|
$es->setQueryResultManipulator('FlickrPhotoTOElasticaSearchHelper'); |
|
|
|
|
973
|
|
|
|
974
|
|
|
//Add filters |
975
|
|
|
foreach ($filters as $key => $value) { |
976
|
|
|
$es->addFilter($key,$value); |
977
|
|
|
} |
978
|
|
|
|
979
|
|
|
$es->showResultsForEmptySearch(); |
980
|
|
|
|
981
|
|
|
$resultList = $es->search($queryText, $fields); |
982
|
|
|
|
983
|
|
|
return $resultList; |
984
|
|
|
} |
985
|
|
|
|
986
|
|
|
} |
987
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: