From 878892b834c965d1edbecdf6f7a6b547673fe6a2 Mon Sep 17 00:00:00 2001 From: Arkezar Date: Sat, 21 Jul 2018 20:13:49 +0200 Subject: [PATCH] Sort universe search results with Levenshtein's function --- app/main/controller/api/universe.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/main/controller/api/universe.php b/app/main/controller/api/universe.php index e59e580b..4651463c 100644 --- a/app/main/controller/api/universe.php +++ b/app/main/controller/api/universe.php @@ -32,6 +32,16 @@ class Universe extends Controller\AccessController { !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);