|
@@ 18-31 (lines=14) @@
|
| 15 |
|
/** |
| 16 |
|
* @group functional |
| 17 |
|
*/ |
| 18 |
|
public function testHistogramAggregation(): void |
| 19 |
|
{ |
| 20 |
|
$agg = new Histogram('hist', 'price', 10); |
| 21 |
|
$agg->setMinimumDocumentCount(0); // should return empty buckets |
| 22 |
|
|
| 23 |
|
$query = new Query(); |
| 24 |
|
$query->addAggregation($agg); |
| 25 |
|
$results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); |
| 26 |
|
|
| 27 |
|
$buckets = $results['buckets']; |
| 28 |
|
$this->assertCount(5, $buckets); |
| 29 |
|
$this->assertEquals(30, $buckets[3]['key']); |
| 30 |
|
$this->assertEquals(2, $buckets[3]['doc_count']); |
| 31 |
|
} |
| 32 |
|
|
| 33 |
|
/** |
| 34 |
|
* @group functional |
|
@@ 36-50 (lines=15) @@
|
| 33 |
|
/** |
| 34 |
|
* @group functional |
| 35 |
|
*/ |
| 36 |
|
public function testHistogramAggregationWithMissing(): void |
| 37 |
|
{ |
| 38 |
|
$agg = new Histogram('hist', 'price', 10); |
| 39 |
|
$agg->setMinimumDocumentCount(0); // should return empty buckets |
| 40 |
|
$agg->setMissing(37); |
| 41 |
|
|
| 42 |
|
$query = new Query(); |
| 43 |
|
$query->addAggregation($agg); |
| 44 |
|
$results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); |
| 45 |
|
|
| 46 |
|
$buckets = $results['buckets']; |
| 47 |
|
$this->assertCount(5, $buckets); |
| 48 |
|
$this->assertEquals(30, $buckets[3]['key']); |
| 49 |
|
$this->assertEquals(3, $buckets[3]['doc_count']); |
| 50 |
|
} |
| 51 |
|
|
| 52 |
|
protected function _getIndexForTest(): Index |
| 53 |
|
{ |