Skip to content

Commit

Permalink
ruflin#1184 Fix for skipped GeoDistanceRangeTest::testGeoPoint, repla…
Browse files Browse the repository at this point in the history
…ce [geo_distance_range] queries with geo distance sorting.
  • Loading branch information
bopop committed Oct 21, 2016
1 parent 00e097c commit 186bdc4
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions test/lib/Elastica/Test/Query/GeoDistanceRangeTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Elastica\Test\Query;

use Elastica\Document;
Expand Down Expand Up @@ -40,34 +41,24 @@ public function testGeoPoint()
$doc2->addGeoPoint('point', 30, 40);
$type->addDocument($doc2);

$index->optimize();
$index->refresh();
// Set geo distance sorting with coordinates near to first doc.
$geoSort =
['_geo_distance' => [
'point' => [
'lat' => 15,
'lon' => 20,
],
'order' => 'asc',
'unit' => 'km',
'distance_type' => 'plane',
]];

// Only one point should be in radius
$query = new Query();
$geoQuery = new GeoDistanceRange(
'point',
['lat' => 30, 'lon' => 40],
['from' => '0km', 'to' => '2km']
);

$query = new Query(new MatchAll());
$query->setPostFilter($geoQuery);
$this->_markSkipped50('[geo_distance_range] queries are no longer supported for geo_point field types. Use geo_distance sort or aggregations ');
$this->assertEquals(1, $type->search($query)->count());

// Both points should be inside
$query = new Query();
$geoQuery = new GeoDistanceRange(
'point',
['lat' => 30, 'lon' => 40],
['gte' => '0km', 'lte' => '4000km']
);
$query = new Query(new MatchAll());
$query->setPostFilter($geoQuery);
$index->refresh();

$this->assertEquals(2, $type->search($query)->count());
$query->setSort($geoSort);
//doc #1 are the nearest to sorting point and must be first in result
$this->assertEquals(1, $type->search($query)->current()->getId());
$this->assertEquals(2, $type->search($query)->next()->getId());
}

/**
Expand Down

0 comments on commit 186bdc4

Please sign in to comment.