| @@ 14-49 (lines=36) @@ | ||
| 11 | /** |
|
| 12 | * @internal |
|
| 13 | */ |
|
| 14 | class GeohashGridTest extends BaseAggregationTest |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @group functional |
|
| 18 | */ |
|
| 19 | public function testGeohashGridAggregation(): void |
|
| 20 | { |
|
| 21 | $agg = new GeohashGrid('hash', 'location'); |
|
| 22 | $agg->setPrecision(3); |
|
| 23 | ||
| 24 | $query = new Query(); |
|
| 25 | $query->addAggregation($agg); |
|
| 26 | $results = $this->_getIndexForTest()->search($query)->getAggregation('hash'); |
|
| 27 | ||
| 28 | $this->assertEquals(2, $results['buckets'][0]['doc_count']); |
|
| 29 | $this->assertEquals(1, $results['buckets'][1]['doc_count']); |
|
| 30 | } |
|
| 31 | ||
| 32 | protected function _getIndexForTest(): Index |
|
| 33 | { |
|
| 34 | $index = $this->_createIndex(); |
|
| 35 | $index->setMapping(new Mapping([ |
|
| 36 | 'location' => ['type' => 'geo_point'], |
|
| 37 | ])); |
|
| 38 | ||
| 39 | $index->addDocuments([ |
|
| 40 | new Document(1, ['location' => ['lat' => 32.849437, 'lon' => -117.271732]]), |
|
| 41 | new Document(2, ['location' => ['lat' => 32.798320, 'lon' => -117.246648]]), |
|
| 42 | new Document(3, ['location' => ['lat' => 37.782439, 'lon' => -122.392560]]), |
|
| 43 | ]); |
|
| 44 | ||
| 45 | $index->refresh(); |
|
| 46 | ||
| 47 | return $index; |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||
| @@ 14-49 (lines=36) @@ | ||
| 11 | /** |
|
| 12 | * @internal |
|
| 13 | */ |
|
| 14 | class GeotileGridAggregationTest extends BaseAggregationTest |
|
| 15 | { |
|
| 16 | /** |
|
| 17 | * @group functional |
|
| 18 | */ |
|
| 19 | public function testGeotileGridAggregation(): void |
|
| 20 | { |
|
| 21 | $agg = new GeotileGridAggregation('tile', 'location'); |
|
| 22 | $agg->setPrecision(7); |
|
| 23 | ||
| 24 | $query = new Query(); |
|
| 25 | $query->addAggregation($agg); |
|
| 26 | $results = $this->_getIndexForTest()->search($query)->getAggregation('tile'); |
|
| 27 | ||
| 28 | $this->assertEquals(2, $results['buckets'][0]['doc_count']); |
|
| 29 | $this->assertEquals(1, $results['buckets'][1]['doc_count']); |
|
| 30 | } |
|
| 31 | ||
| 32 | protected function _getIndexForTest(): Index |
|
| 33 | { |
|
| 34 | $index = $this->_createIndex(); |
|
| 35 | $index->setMapping(new Mapping([ |
|
| 36 | 'location' => ['type' => 'geo_point'], |
|
| 37 | ])); |
|
| 38 | ||
| 39 | $index->addDocuments([ |
|
| 40 | new Document(1, ['location' => ['lat' => 32.849437, 'lon' => -117.271732]]), |
|
| 41 | new Document(2, ['location' => ['lat' => 32.798320, 'lon' => -117.246648]]), |
|
| 42 | new Document(3, ['location' => ['lat' => 37.782439, 'lon' => -122.392560]]), |
|
| 43 | ]); |
|
| 44 | ||
| 45 | $index->refresh(); |
|
| 46 | ||
| 47 | return $index; |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||