Skip to content
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

Adds shape type constants to GeoShapeQuery #345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ before_script:
- composer install --no-interaction --prefer-dist
script:
- wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200
- vendor/bin/phpunit --coverage-clover=coverage.xml
- XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover=coverage.xml
- vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor/ ./
after_script:
- travis_retry bash <(curl -s https://codecov.io/bash)
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