From 1b57a1b23e54fce5e3a72e6bd622313cfe943d25 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:48:58 +0200 Subject: [PATCH 1/6] update regions_sample file --- test/Widget/regions_sample.json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/Widget/regions_sample.json b/test/Widget/regions_sample.json index d8fbca95..aa415d5a 100644 --- a/test/Widget/regions_sample.json +++ b/test/Widget/regions_sample.json @@ -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" @@ -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" From 48077b1ae94e04bdfdedc2897b7bb1f8fbf73d66 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:49:08 +0200 Subject: [PATCH 2/6] make test for informal citynames. --- test/Widget/RegionServiceTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/Widget/RegionServiceTest.php b/test/Widget/RegionServiceTest.php index aad8f1a9..f63e378c 100644 --- a/test/Widget/RegionServiceTest.php +++ b/test/Widget/RegionServiceTest.php @@ -60,6 +60,19 @@ public function it_will_find_match_the_start_of_a_city_name() ); } + /** + * @test + */ + public function it_does_not_match_with_informal_names() + { + $this->assertEquals( + [ + 'nis-24008C' => 'Molenbeek-Wersbeek (Bekkevoort)', + ], + $this->regionService->getAutocompletResults('Molenbeek') + ); + } + /** * @test */ From 0ec8b24f40111493460f52465e6d7ec7d3093baa Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:52:10 +0200 Subject: [PATCH 3/6] linting --- test/Widget/RegionServiceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Widget/RegionServiceTest.php b/test/Widget/RegionServiceTest.php index f63e378c..145b610b 100644 --- a/test/Widget/RegionServiceTest.php +++ b/test/Widget/RegionServiceTest.php @@ -63,7 +63,7 @@ public function it_will_find_match_the_start_of_a_city_name() /** * @test */ - public function it_does_not_match_with_informal_names() + public function it_does_not_match_with_informal_names(): void { $this->assertEquals( [ From b4cd5d45583b81b158768b46b7c2d4d65c6984c7 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:07:33 +0200 Subject: [PATCH 4/6] add logic for informal names --- src/Widget/RegionService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Widget/RegionService.php b/src/Widget/RegionService.php index d64cc96e..ee9894b4 100644 --- a/src/Widget/RegionService.php +++ b/src/Widget/RegionService.php @@ -56,6 +56,10 @@ public function getAutocompletResults($searchString, $language = 'nl') if (strpos(strtolower($translatedRegion), '(' . $searchString) !== false) { $matches[$region->key] = $translatedRegion; } + // This is done to add informal municipality names without prefixes like Saint + if (strpos(strtolower($translatedRegion), '-' . $searchString) !== false) { + $matches[$region->key] = $translatedRegion; + } } } From bd37de02a98c301f0ab97184321f4d3788dd8bf6 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Thu, 22 Aug 2024 13:07:37 +0200 Subject: [PATCH 5/6] rename test --- test/Widget/RegionServiceTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/Widget/RegionServiceTest.php b/test/Widget/RegionServiceTest.php index 145b610b..23947ff8 100644 --- a/test/Widget/RegionServiceTest.php +++ b/test/Widget/RegionServiceTest.php @@ -63,10 +63,12 @@ public function it_will_find_match_the_start_of_a_city_name() /** * @test */ - public function it_does_not_match_with_informal_names(): void + 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') From fd2162b875210cc70eb1f4ecb59d65ce8e41c410 Mon Sep 17 00:00:00 2001 From: JonasVHG <4658984+JonasVHG@users.noreply.github.com> Date: Thu, 22 Aug 2024 14:19:48 +0200 Subject: [PATCH 6/6] only lower $translatedRegion once for 3 comparisons. --- src/Widget/RegionService.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Widget/RegionService.php b/src/Widget/RegionService.php index ee9894b4..8ed871cc 100644 --- a/src/Widget/RegionService.php +++ b/src/Widget/RegionService.php @@ -47,17 +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 - if (strpos(strtolower($translatedRegion), '-' . $searchString) !== false) { + if (strpos($compareString, '-' . $searchString) !== false) { $matches[$region->key] = $translatedRegion; } }