Skip to content

Commit

Permalink
remove unused function sortByLevenshtein()
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasVHG committed Aug 6, 2024
1 parent 9113868 commit e6698a8
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 41 deletions.
22 changes: 0 additions & 22 deletions src/Widget/RegionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,4 @@ public function getItemByTranslatedName($translatedName, $translatedLanguage)
}
}
}

/**
* Sort items according to Levenshtein distance, the higher the match the higher the value.
* But usort sorts by default from small to large, first item has a smaller value.
* So the high Levenshtein values need to get before the smaller onces and therefore they need to return -1
*
* @param $matches
* @param $searchString
* @return $matches
*/
public function sortByLevenshtein($matches, $searchString)
{
usort(
$matches,
function ($a, $b) use ($searchString) {
$levA = levenshtein($searchString, $a);
$levB = levenshtein($searchString, $b);
return $levA === $levB ? 0 : ($levA > $levB ? -1 : 1);
}
);
return $matches;
}
}
19 changes: 0 additions & 19 deletions test/Widget/RegionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,4 @@ public function it_will_return_null_if_a_name_does_not_match(): void
$this->regionService->getItemByName('Liezele')
);
}

/**
* @test
*/
public function it_can_sort_by_levenshtein(): void
{
$searchString = 'Zele';
$this->assertEquals(
[
'Zele + deelgemeenten',
'Zelem (Halen)',
'Zele (Zele)',
],
$this->regionService->sortByLevenshtein(
$this->regionService->getAutocompletResults($searchString),
$searchString
)
);
}
}

0 comments on commit e6698a8

Please sign in to comment.