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 9771144a02d1c76a779e80a5c5873703b48eee91..054c6af56bdd4ac96688649baca692a4d325a956 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', ],