Skip to content

Commit

Permalink
Adds shape type constants to GeoShapeQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
j13k committed Dec 16, 2020
1 parent b4c3c89 commit be2d341
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/Query/Geo/GeoShapeQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ class GeoShapeQuery implements BuilderInterface
const WITHIN = 'within';
const CONTAINS = 'contains';

/*
* Available shape types for addShape() $type param.
*
* @link https://www.elastic.co/guide/en/elasticsearch/reference/current/geo-shape.html#input-structure
*/
const SHAPE_TYPE_POINT = 'point';
const SHAPE_TYPE_LINESTRING = 'linestring';
const SHAPE_TYPE_POLYGON = 'polygon';
const SHAPE_TYPE_MULTIPOINT = 'multipoint';
const SHAPE_TYPE_MULTILINESTRING = 'multilinestring';
const SHAPE_TYPE_MULTIPOLYGON = 'multipolygon';
const SHAPE_TYPE_GEOMETRYCOLLECTION = 'geometrycollection';
const SHAPE_TYPE_ENVELOPE = 'envelope';
const SHAPE_TYPE_CIRCLE = 'circle';

/**
* @var array
*/
Expand Down
9 changes: 7 additions & 2 deletions tests/Unit/Query/Geo/GeoShapeQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@ class GeoShapeQueryTest extends \PHPUnit\Framework\TestCase
public function testToArray()
{
$filter = new GeoShapeQuery(['param1' => 'value1']);
$filter->addShape('location', 'envelope', [[13, 53], [14, 52]], GeoShapeQuery::INTERSECTS);
$filter->addShape(
'location',
GeoShapeQuery::SHAPE_TYPE_ENVELOPE,
[[13, 53], [14, 52]],
GeoShapeQuery::INTERSECTS
);

$expected = [
'geo_shape' => [
'location' => [
'shape' => [
'type' => 'envelope',
'type' => GeoShapeQuery::SHAPE_TYPE_ENVELOPE,
'coordinates' => [[13, 53], [14, 52]],
],
'relation' => 'intersects'
Expand Down

0 comments on commit be2d341

Please sign in to comment.