From 2546621c59d62a6c3147e879eee4b70e7a114524 Mon Sep 17 00:00:00 2001 From: Daku Date: Sat, 18 Jun 2016 13:18:59 +0100 Subject: [PATCH] sort autocomplete by score + show score --- ext/autocomplete/main.php | 10 ++++++++-- ext/autocomplete/script.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ext/autocomplete/main.php b/ext/autocomplete/main.php index cd373c63..1dfb81f4 100644 --- a/ext/autocomplete/main.php +++ b/ext/autocomplete/main.php @@ -20,8 +20,14 @@ class AutoComplete extends Extension { $SQLarr['limit'] = $_GET["limit"]; } - $res = $database->get_col( - "SELECT tag FROM tags WHERE tag LIKE :search AND count > 0 $limitSQL", $SQLarr); + $res = $database->get_pairs(" + SELECT tag, count + FROM tags + WHERE tag LIKE :search + AND count > 0 + ORDER BY count DESC + $limitSQL", $SQLarr + ); $page->set_mode("data"); $page->set_type("application/json"); diff --git a/ext/autocomplete/script.js b/ext/autocomplete/script.js index b2f26384..87ccbf93 100644 --- a/ext/autocomplete/script.js +++ b/ext/autocomplete/script.js @@ -18,10 +18,10 @@ $(function(){ dataType : 'json', type : 'GET', success : function (data) { - response($.map(data, function (item) { + response($.map(data, function (count, item) { item = (isNegative ? '-'+item : item); return { - label : item, + label : item + ' ('+count+')', value : item } }));