Update Taglist.php

For showing better results.
This commit is contained in:
Neo Morina 2018-08-23 11:39:09 +02:00 committed by GitHub
parent 28781956fe
commit 8093e6a549
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -79,6 +79,16 @@ class Taglist extends Etemplate\Widget
{ {
$results[] = array('id' => $id, 'label' => $name); $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 // switch regular JSON response handling off
Api\Json\Request::isJSONRequest(false); Api\Json\Request::isJSONRequest(false);