From 8093e6a54909a33ee09d0b0a06a30d1c639fe194 Mon Sep 17 00:00:00 2001 From: Neo Morina Date: Thu, 23 Aug 2018 11:39:09 +0200 Subject: [PATCH] Update Taglist.php For showing better results. --- api/src/Etemplate/Widget/Taglist.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/src/Etemplate/Widget/Taglist.php b/api/src/Etemplate/Widget/Taglist.php index 78abb77baf..b779892c14 100644 --- a/api/src/Etemplate/Widget/Taglist.php +++ b/api/src/Etemplate/Widget/Taglist.php @@ -79,6 +79,16 @@ class Taglist extends Etemplate\Widget { $results[] = array('id' => $id, 'label' => $name); } + + usort($results, function ($a, $b) use ($query) { + $a_label = is_array($a["label"]) ? $a["label"]["label"] : $a["label"]; + $b_label = is_array($b["label"]) ? $b["label"]["label"] : $b["label"]; + + similar_text($query, $a_label, $percent_a); + similar_text($query, $b_label, $percent_b); + return $percent_a === $percent_b ? 0 : ($percent_a > $percent_b ? -1 : 1); + }); + // switch regular JSON response handling off Api\Json\Request::isJSONRequest(false);