Skip to content

Commit

Permalink
Adds shape type constants to GeoShapeQuery
Browse files Browse the repository at this point in the history
Also updates associated unit test
  • Loading branch information
j13k committed Dec 16, 2020
1 parent b4c3c89 commit e97f6b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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
7 changes: 6 additions & 1 deletion tests/Unit/Query/Geo/GeoShapeQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ 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' => [
Expand Down

0 comments on commit e97f6b3

Please sign in to comment.