| @@ 22-51 (lines=30) @@ | ||
| 19 | /** |
|
| 20 | * @group functional |
|
| 21 | */ |
|
| 22 | public function testDateHistogramAggregation(): void |
|
| 23 | { |
|
| 24 | $agg = new DateHistogram('hist', 'created'); |
|
| 25 | ||
| 26 | $version = $this->_getVersion(); |
|
| 27 | ||
| 28 | if (\version_compare($version, '7.2') < 0) { |
|
| 29 | $agg->setParam('interval', '1h'); |
|
| 30 | } else { |
|
| 31 | $agg->setFixedInterval('1h'); |
|
| 32 | } |
|
| 33 | ||
| 34 | $query = new Query(); |
|
| 35 | $query->addAggregation($agg); |
|
| 36 | $results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); |
|
| 37 | ||
| 38 | $docCount = 0; |
|
| 39 | $nonDocCount = 0; |
|
| 40 | foreach ($results['buckets'] as $bucket) { |
|
| 41 | if (1 == $bucket['doc_count']) { |
|
| 42 | ++$docCount; |
|
| 43 | } else { |
|
| 44 | ++$nonDocCount; |
|
| 45 | } |
|
| 46 | } |
|
| 47 | // 3 Documents that were added |
|
| 48 | $this->assertEquals(3, $docCount); |
|
| 49 | // 1 document that was generated in between for the missing hour |
|
| 50 | $this->assertEquals(1, $nonDocCount); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * @group unit |
|
| @@ 79-108 (lines=30) @@ | ||
| 76 | /** |
|
| 77 | * @group functional |
|
| 78 | */ |
|
| 79 | public function testDateHistogramCalendarAggregation(): void |
|
| 80 | { |
|
| 81 | $agg = new DateHistogram('hist', 'created'); |
|
| 82 | ||
| 83 | $version = $this->_getVersion(); |
|
| 84 | ||
| 85 | if (\version_compare($version, '7.2') < 0) { |
|
| 86 | $agg->setParam('interval', '1h'); |
|
| 87 | } else { |
|
| 88 | $agg->setCalendarInterval('1h'); |
|
| 89 | } |
|
| 90 | ||
| 91 | $query = new Query(); |
|
| 92 | $query->addAggregation($agg); |
|
| 93 | $results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); |
|
| 94 | ||
| 95 | $docCount = 0; |
|
| 96 | $nonDocCount = 0; |
|
| 97 | foreach ($results['buckets'] as $bucket) { |
|
| 98 | if (1 == $bucket['doc_count']) { |
|
| 99 | ++$docCount; |
|
| 100 | } else { |
|
| 101 | ++$nonDocCount; |
|
| 102 | } |
|
| 103 | } |
|
| 104 | // 3 Documents that were added |
|
| 105 | $this->assertEquals(3, $docCount); |
|
| 106 | // 1 document that was generated in between for the missing hour |
|
| 107 | $this->assertEquals(1, $nonDocCount); |
|
| 108 | } |
|
| 109 | ||
| 110 | /** |
|
| 111 | * @group functional |
|
| @@ 113-144 (lines=32) @@ | ||
| 110 | /** |
|
| 111 | * @group functional |
|
| 112 | */ |
|
| 113 | public function testDateHistogramAggregationWithMissing(): void |
|
| 114 | { |
|
| 115 | $agg = new DateHistogram('hist', 'created'); |
|
| 116 | ||
| 117 | $version = $this->_getVersion(); |
|
| 118 | ||
| 119 | if (\version_compare($version, '7.2') < 0) { |
|
| 120 | $agg->setParam('interval', '1h'); |
|
| 121 | } else { |
|
| 122 | $agg->setFixedInterval('1h'); |
|
| 123 | } |
|
| 124 | ||
| 125 | $agg->setMissing('2014-01-29T04:20:00'); |
|
| 126 | ||
| 127 | $query = new Query(); |
|
| 128 | $query->addAggregation($agg); |
|
| 129 | $results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); |
|
| 130 | ||
| 131 | $docCount = 0; |
|
| 132 | $nonDocCount = 0; |
|
| 133 | foreach ($results['buckets'] as $bucket) { |
|
| 134 | if (1 == $bucket['doc_count']) { |
|
| 135 | ++$docCount; |
|
| 136 | } else { |
|
| 137 | ++$nonDocCount; |
|
| 138 | } |
|
| 139 | } |
|
| 140 | // 3 Documents that were added |
|
| 141 | $this->assertEquals(4, $docCount); |
|
| 142 | // 1 document that was generated in between for the missing hour |
|
| 143 | $this->assertEquals(1, $nonDocCount); |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * @group functional |
|