-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the geo_centroid aggregation #1150
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d6a300e
Added the geo_centroid aggregation
coreation 05382db
Added GeoCentroid to the changelog and added GeoCentroid integration …
coreation a2188bb
Merge remote-tracking branch 'upstream/master'
coreation c17c314
Added GeoCentroid aggregation class to the changelog
coreation cdd7cf8
Removed duplicate line in the changelog
coreation File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file based on the | |
|
||
### Added | ||
- Elastica\QueryBuilder\DSL\Query::geo_distance | ||
- Elastica\Aggregation\GeoCentroid | ||
|
||
### Improvements | ||
- Set PHP 7.0 as default development version | ||
|
@@ -38,6 +39,7 @@ All notable changes to this project will be documented in this file based on the | |
- Fix php notice on `\Elastica\Index::getAliases()` if index has no aliases [#1078](https://github.com/ruflin/Elastica/issues/1078) | ||
|
||
### Added | ||
- `Elastica\Aggregations\GeoCentroid` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a newline afterwards? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like your merge now caused it to be added twice. This one should be removed. |
||
- Update elasticsearch build dependency to elasticsearch 2.3.2 [#1084](https://github.com/ruflin/Elastica/pull/1084) | ||
|
||
### Improvements | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Elastica\Aggregation; | ||
|
||
use Elastica\Exception\InvalidException; | ||
|
||
/** | ||
* Class GeoCentroid. | ||
* | ||
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-geocentroid-aggregation.html | ||
*/ | ||
class GeoCentroid extends AbstractAggregation | ||
{ | ||
/** | ||
* @param string $name the name of this aggregation | ||
* @param string $field the field on which to perform this aggregation | ||
*/ | ||
public function __construct($name, $field) | ||
{ | ||
parent::__construct($name); | ||
$this->setField($field); | ||
} | ||
|
||
/** | ||
* Set the field for this aggregation. | ||
* | ||
* @param string $field the name of the document field on which to perform this aggregation | ||
* | ||
* @return $this | ||
*/ | ||
public function setField($field) | ||
{ | ||
return $this->setParam('field', $field); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
namespace Elastica\Test\Aggregation; | ||
|
||
use Elastica\Aggregation\GeoCentroid; | ||
use Elastica\Document; | ||
use Elastica\Query; | ||
use Elastica\Type\Mapping; | ||
|
||
class GeoCentroidTest extends BaseAggregationTest | ||
{ | ||
protected function _getIndexForTest() | ||
{ | ||
$index = $this->_createIndex(); | ||
$type = $index->getType('test'); | ||
|
||
$type->setMapping(new Mapping(null, array( | ||
'location' => array('type' => 'geo_point'), | ||
))); | ||
|
||
$type->addDocuments(array( | ||
new Document(1, array('location' => array('lat' => 32.849437, 'lon' => -117.271732))), | ||
new Document(2, array('location' => array('lat' => 32.798320, 'lon' => -117.246648))), | ||
new Document(3, array('location' => array('lat' => 37.782439, 'lon' => -122.392560))), | ||
)); | ||
|
||
$index->refresh(); | ||
|
||
return $index; | ||
} | ||
|
||
/** | ||
* @group functional | ||
*/ | ||
public function testGeohashGridAggregation() | ||
{ | ||
$agg = new GeoCentroid('centroid', 'location'); | ||
|
||
$query = new Query(); | ||
$query->addAggregation($agg); | ||
$results = $this->_getIndexForTest()->search($query)->getAggregation('centroid'); | ||
|
||
$this->assertEquals(34.476731875911, $results['location']['lat']); | ||
$this->assertEquals(-118.97031342611, $results['location']['lon']); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you already edit the changelog, you could also add #1150 at the end (see change examples below)