Skip to content
Snippets Groups Projects
Commit 7b6ad65b authored by John Fitzpatrick's avatar John Fitzpatrick Committed by Simonas Šerlinskas
Browse files

Added relation parameter for pre-indexed geo_shape query (#290)

* Added relation parameter for pre-indexed geo_shape query

Fixes #289.

* Update .travis.yml

Added conditional to check for `GITHUB_COMPOSER_AUTH` env var
parent db57301d
No related branches found
No related tags found
No related merge requests found
......@@ -12,11 +12,11 @@ install:
- tar -xzf elasticsearch-${ES_VERSION}.tar.gz
- ./elasticsearch-${ES_VERSION}/bin/elasticsearch -d
before_script:
- composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH
- if [ "$GITHUB_COMPOSER_AUTH" ]; then composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH; fi
- 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
- vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor/ ./
after_script:
- travis_retry bash <(curl -s https://codecov.io/bash)
\ No newline at end of file
- travis_retry bash <(curl -s https://codecov.io/bash)
......@@ -88,11 +88,26 @@ class GeoShapeQuery implements BuilderInterface
* @param string $id The ID of the document that containing the pre-indexed shape.
* @param string $type Name of the index where the pre-indexed shape is.
* @param string $index Index type where the pre-indexed shape is.
* @param string $relation Spatial relation.
* @param string $path The field specified as path containing the pre-indexed shape.
* @param array $parameters Additional parameters.
*/
public function addPreIndexedShape($field, $id, $type, $index, $path, array $parameters = [])
{
public function addPreIndexedShape(
$field,
$id,
$type,
$index,
$path,
$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 6 in addShape is deprecated', E_USER_DEPRECATED);
}
$filter = array_merge(
$parameters,
[
......@@ -103,7 +118,10 @@ class GeoShapeQuery implements BuilderInterface
]
);
$this->fields[$field]['indexed_shape'] = $filter;
$this->fields[$field] = [
'indexed_shape' => $filter,
'relation' => $relation,
];
}
/**
......
......@@ -45,7 +45,7 @@ class GeoShapeQueryTest extends \PHPUnit\Framework\TestCase
public function testToArrayIndexed()
{
$filter = new GeoShapeQuery(['param1' => 'value1']);
$filter->addPreIndexedShape('location', 'DEU', 'countries', 'shapes', 'location');
$filter->addPreIndexedShape('location', 'DEU', 'countries', 'shapes', 'location', GeoShapeQuery::WITHIN);
$expected = [
'geo_shape' => [
......@@ -56,6 +56,7 @@ class GeoShapeQueryTest extends \PHPUnit\Framework\TestCase
'index' => 'shapes',
'path' => 'location',
],
'relation' => 'within'
],
'param1' => 'value1',
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment