diff --git a/composer.json b/composer.json index 8584adbb68504c08f7b7ef2a607c58388d4f377f..dcc16c4301cbaa68fe7cb96e4d11cf1692ef94c9 100644 --- a/composer.json +++ b/composer.json @@ -11,15 +11,14 @@ } ], "require": { - "php": ">=7.0", - "symfony/serializer": "~3.0|~4.0", - "paragonie/random_compat": "^2.0", - "elasticsearch/elasticsearch": "~6.0" + "php": "^7.0", + "symfony/serializer": "^3.0|^4.0", + "paragonie/random_compat": "^1.0|^2.0" }, "require-dev": { - "phpunit/phpunit": "~6.0", - "squizlabs/php_codesniffer": "~3.0", - "satooshi/php-coveralls": "~2.0" + "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "^3.0", + "satooshi/php-coveralls": "^2.0" }, "autoload": { "psr-4": { diff --git a/src/Query/Geo/GeoShapeQuery.php b/src/Query/Geo/GeoShapeQuery.php index 9e51537a4f0404cb3df287eb269ada244646a0da..584f335acb16d922685b433b40bd067545538487 100644 --- a/src/Query/Geo/GeoShapeQuery.php +++ b/src/Query/Geo/GeoShapeQuery.php @@ -23,6 +23,11 @@ class GeoShapeQuery implements BuilderInterface { use ParametersTrait; + const INTERSECTS = 'intersects'; + const DISJOINT = 'disjoint'; + const WITHIN = 'within'; + const CONTAINS = 'contains'; + /** * @var array */ @@ -50,10 +55,18 @@ class GeoShapeQuery implements BuilderInterface * @param string $field Field name. * @param string $type Shape type. * @param array $coordinates Shape coordinates. + * @param string $relation Spatial relation. * @param array $parameters Additional parameters. */ - public function addShape($field, $type, array $coordinates, array $parameters = []) + public function addShape($field, $type, array $coordinates, $relation = self::INTERSECTS, array $parameters = []) { + // TODO: remove this in the next major version + if (is_array($relation)) { + $parameters = $relation; + $relation = self::INTERSECTS; + trigger_error('$parameters as parameter 4 in addShape is deprecated', E_USER_DEPRECATED); + } + $filter = array_merge( $parameters, [ @@ -62,7 +75,10 @@ class GeoShapeQuery implements BuilderInterface ] ); - $this->fields[$field]['shape'] = $filter; + $this->fields[$field] = [ + 'shape' => $filter, + 'relation' => $relation, + ]; } /** diff --git a/tests/Unit/Query/Geo/GeoShapeQueryTest.php b/tests/Unit/Query/Geo/GeoShapeQueryTest.php index a0135bf78192b75a62f81449c74ff687e6ac1ec5..4a7a43273d6fc3d0c92b162de6639503f51b39e8 100644 --- a/tests/Unit/Query/Geo/GeoShapeQueryTest.php +++ b/tests/Unit/Query/Geo/GeoShapeQueryTest.php @@ -21,7 +21,7 @@ class GeoShapeQueryTest extends \PHPUnit\Framework\TestCase public function testToArray() { $filter = new GeoShapeQuery(['param1' => 'value1']); - $filter->addShape('location', 'envelope', [[13, 53], [14, 52]]); + $filter->addShape('location', 'envelope', [[13, 53], [14, 52]], GeoShapeQuery::INTERSECTS); $expected = [ 'geo_shape' => [ @@ -30,6 +30,7 @@ class GeoShapeQueryTest extends \PHPUnit\Framework\TestCase 'type' => 'envelope', 'coordinates' => [[13, 53], [14, 52]], ], + 'relation' => 'intersects' ], 'param1' => 'value1', ],