Skip to content

Commit

Permalink
Sort universe search results with Levenshtein's function
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkezar committed Jul 21, 2018
1 parent 63ea379 commit 98a523c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/main/controller/api/universe.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public function search(\Base $f3, $params){
!empty($categories)
){
$universeNameData = Ccp\Universe::searchUniverseNameData($categories, $search);

foreach($categories as &$category) {
if(!empty($universeNameData[$category])){
usort($universeNameData[$category], function($a, $b) use ($search) {
$levA = levenshtein($search, strtolower($a["name"]));
$levB = levenshtein($search, strtolower($b["name"]));
return $levA == $levB ? 0 : ($levA > $levB ? 1 : -1);
});
}
}
}

echo json_encode($universeNameData);
Expand Down

0 comments on commit 98a523c

Please sign in to comment.