diff --git a/src/app/Packages/Domains/WorldHeritage/Adapter/AlgoliaWorldHeritageSearchAdapter.php b/src/app/Packages/Domains/WorldHeritage/Adapter/AlgoliaWorldHeritageSearchAdapter.php index 97f72711..f4aab0ad 100644 --- a/src/app/Packages/Domains/WorldHeritage/Adapter/AlgoliaWorldHeritageSearchAdapter.php +++ b/src/app/Packages/Domains/WorldHeritage/Adapter/AlgoliaWorldHeritageSearchAdapter.php @@ -127,6 +127,12 @@ public function search( 'page' => $firstPage, 'hitsPerPage' => $perPage, 'filters' => $hasAnyFilter ? implode(' AND ', $filters) : null, + /** + * Only the id is ever read from the response (see below): + * the full record is re-fetched from the DB via findByIdsPreserveOrder. + * Restrict the payload accordingly. + */ + 'attributesToRetrieve' => ['objectID', 'id'], ], static fn ($v) => $v !== null, ), @@ -156,12 +162,12 @@ public function search( /** * Build an OR-filter that can match different country input shapes: - * - English: country / state_party (exact match) + * - English: country (exact match) * - Japanese: country_name_jp (exact match) * - ISO3-like: state_party_codes: * * Example output: - * (country:"Japan" OR state_party:"Japan" OR country_name_jp:"日本" OR state_party_codes:JPN) + * (country:"Japan" OR country_name_jp:"日本" OR state_party_codes:JPN) */ private function buildCountryOrFilter(string $raw): string { @@ -170,7 +176,6 @@ private function buildCountryOrFilter(string $raw): string $orParts = [ 'country:"' . $quoted . '"', - 'state_party:"' . $quoted . '"', 'country_name_jp:"' . $quoted . '"', ]; diff --git a/src/app/Packages/Domains/WorldHeritage/Tests/AlgoliaWorldHeritageSearchAdapterTest.php b/src/app/Packages/Domains/WorldHeritage/Tests/AlgoliaWorldHeritageSearchAdapterTest.php index cc1db094..9ce743be 100644 --- a/src/app/Packages/Domains/WorldHeritage/Tests/AlgoliaWorldHeritageSearchAdapterTest.php +++ b/src/app/Packages/Domains/WorldHeritage/Tests/AlgoliaWorldHeritageSearchAdapterTest.php @@ -52,6 +52,7 @@ public function test_search_builds_algolia_params_with_filters_and_paging(): voi 'filters' => 'state_party_codes:ECU AND study_region:"South America" AND category:"Natural" ' . 'AND year_inscribed >= 1978 AND year_inscribed <= 1980', + 'attributesToRetrieve' => ['objectID', 'id'], ]; $this->client @@ -76,4 +77,48 @@ public function test_search_builds_algolia_params_with_filters_and_paging(): voi $this->assertSame(2, $result->currentPage); $this->assertSame(1, $result->lastPage); } + + public function test_search_by_country_name_without_iso3_does_not_filter_on_state_party(): void + { + $indexName = 'world_heritage'; + $adapter = new AlgoliaWorldHeritageSearchAdapter($this->client, $indexName); + + $q = new AlgoliaSearchListQuery( + keyword: null, + countryName: 'Ecuador', + countryIso3: null, + region: null, + category: null, + yearFrom: null, + yearTo: null, + criteria: [], + isEndangered: null, + currentPage: 1, + perPage: 30, + ); + + $expectedParams = [ + 'query' => '', + 'page' => 0, + 'hitsPerPage' => 30, + 'filters' => '(country:"Ecuador" OR country_name_jp:"Ecuador")', + 'attributesToRetrieve' => ['objectID', 'id'], + ]; + + $this->client + ->shouldReceive('searchSingleIndex') + ->once() + ->with($indexName, $expectedParams) + ->andReturn([ + 'hits' => [], + 'nbHits' => 0, + 'nbPages' => 0, + 'page' => 0, + 'hitsPerPage' => 30, + ]); + + $result = $adapter->search($q, currentPage: 1, perPage: 30); + + $this->assertSame([], $result->ids); + } }