Skip to content

Commit

Permalink
Add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Sep 9, 2024
1 parent 313db45 commit 7a37591
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions tests/Functional/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ class SearchTest extends TestCase
*/
public static function distanceFilterProvider(): iterable
{
yield [
'distance' => 4_587_758,
];
yield [
'distance' => 4_587_759,
];
yield ['distance' => 4_587_758];
yield ['distance' => 4_587_759];
yield ['distance' => 4_642_695];
yield ['distance' => 4_642_696]; // TODO all distanced over >= 4_642_696 does not work
yield ['distance' => 6_000_000]; // TODO all distanced over >= 4_587_759 does not work
}

public static function emptyFilterProvider(): \Generator
Expand Down Expand Up @@ -1100,6 +1099,50 @@ public function testGeoSearchDistances(int $distance): void

$searchParameters = SearchParameters::create()
->withFilter('_geoRadius(location, 52.52, 13.405, ' . $distance . ')' /* Berlin */)
->withAttributesToRetrieve(['id', 'title', 'location'])
;

$this->searchAndAssertResults($loupe, $searchParameters, [
'hits' => [
[
'id' => '2',
'title' => 'London',
'location' => [
// ~ 932 km
'lat' => 51.5074,
'lng' => -0.1278,
],
],
[
'id' => '3',
'title' => 'Vienna',
'location' => [
// ~ 545 km
'lat' => 48.2082,
'lng' => 16.3738,
],
],
],
'query' => '',
'hitsPerPage' => 20,
'page' => 1,
'totalPages' => 1,
'totalHits' => 2,
]);
}

public function testGeoSearchDistanceWithoutSort(): void
{
$configuration = Configuration::create()
->withFilterableAttributes(['location'])
->withSearchableAttributes(['title'])
;

$loupe = $this->createLoupe($configuration);
$this->indexFixture($loupe, 'locations');

$searchParameters = SearchParameters::create()
->withFilter('_geoRadius(location, 52.52, 13.405, 1000000)' /* Berlin */)
->withAttributesToRetrieve(['id', 'title', 'location', '_geoDistance(location)'])
;

Expand All @@ -1113,6 +1156,7 @@ public function testGeoSearchDistances(int $distance): void
'lat' => 51.5074,
'lng' => -0.1278,
],
'_geoDistance(location)' => 932_000, // TODO correct value
],
[
'id' => '3',
Expand All @@ -1122,6 +1166,7 @@ public function testGeoSearchDistances(int $distance): void
'lat' => 48.2082,
'lng' => 16.3738,
],
'_geoDistance(location)' => 545_000, // TODO correct value
],
],
'query' => '',
Expand Down

0 comments on commit 7a37591

Please sign in to comment.