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

WID-575 Molenbeek Edge case #418

Merged
merged 6 commits into from
Aug 22, 2024
Merged
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
9 changes: 7 additions & 2 deletions src/Widget/RegionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ public function getAutocompletResults($searchString, $language = 'nl')
$translatedRegion = $region->name;
}
}
$compareString = strtolower($translatedRegion);
// This is done to find cities & towns with short names which also match lots of other cities & towns
// e.g., Zele or Egem
if (strpos(strtolower($translatedRegion), $searchString) === 0) {
if (strpos($compareString, $searchString) === 0) {
$matches[$region->key] = $translatedRegion;
}
// This is done to add the submunicipalities when searching for a municipality.
if (strpos(strtolower($translatedRegion), '(' . $searchString) !== false) {
if (strpos($compareString, '(' . $searchString) !== false) {
$matches[$region->key] = $translatedRegion;
}
// This is done to add informal municipality names without prefixes like Saint
JonasVHG marked this conversation as resolved.
Show resolved Hide resolved
if (strpos($compareString, '-' . $searchString) !== false) {
$matches[$region->key] = $translatedRegion;
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/Widget/RegionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ public function it_will_find_match_the_start_of_a_city_name()
);
}

/**
* @test
*/
public function it_will_match_with_informal_names(): void
{
$this->assertEquals(
[
'nis-21012' => 'Sint-Jans-Molenbeek + deelgemeenten',
'nis-21012A' => 'Sint-Jans-Molenbeek (Sint-Jans-Molenbeek)',
'nis-24008C' => 'Molenbeek-Wersbeek (Bekkevoort)',
],
$this->regionService->getAutocompletResults('Molenbeek')
);
}

/**
* @test
*/
Expand Down
24 changes: 24 additions & 0 deletions test/Widget/regions_sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
"name":"Liezele (Puurs-Sint-Amands)",
"key":"nis-12030D"
},
{
"name": "Sint-Jans-Molenbeek + deelgemeenten",
"key": "nis-21012"
},
{
"name": "Sint-Jans-Molenbeek (Sint-Jans-Molenbeek)",
"key": "nis-21012A"
},
{
"name":"Vollezele (Galmaarden)",
"key":"nis-23023B"
Expand All @@ -11,6 +19,22 @@
"name":"Mazenzele (Opwijk)",
"key":"nis-23060B"
},
{
"name": "Bekkevoort + deelgemeenten",
"key": "nis-24008"
},
{
"name": "Bekkevoort (Bekkevoort)",
"key": "nis-24008A"
},
{
"name": "Assent (Bekkevoort)",
"key": "nis-24008B"
},
{
"name": "Molenbeek-Wersbeek (Bekkevoort)",
"key": "nis-24008C"
},
{
"name":"Gentinnes (Chastre)",
"key":"nis-25117D"
Expand Down
Loading