From 24f5024db3c8e8606cce58d756f33db9b9c61382 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 27 Oct 2013 23:14:48 +0100 Subject: [PATCH] Fixed tag autocompletion It yielded too many results in some cases. --- public_html/media/js/core.js | 9 +++++---- src/Controllers/TagController.php | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js index 4ba947c9..072e145f 100644 --- a/public_html/media/js/core.js +++ b/public_html/media/js/core.js @@ -158,10 +158,11 @@ $(function() source: function(request, response) { var term = extractLast(request.term); - $.get(searchInput.attr('data-autocomplete-url') + '?json', {filter: term}, function(data) - { - response($.map(data.tags, function(tag) { return { label: tag, value: tag }; })); - }); + if (term != '') + $.get(searchInput.attr('data-autocomplete-url') + '?json', {filter: term}, function(data) + { + response($.map(data.tags, function(tag) { return { label: tag, value: tag }; })); + }); }, focus: function() { diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php index 8156ed7a..d22db520 100644 --- a/src/Controllers/TagController.php +++ b/src/Controllers/TagController.php @@ -17,7 +17,7 @@ class TagController $dbQuery->from('tag'); $dbQuery->innerJoin('post_tag'); $dbQuery->on('tag.id = post_tag.tag_id'); - if ($suppliedFilter) + if ($suppliedFilter !== null) { if (strlen($suppliedFilter) >= 3) $suppliedFilter = '%' . $suppliedFilter; @@ -26,7 +26,7 @@ class TagController } $dbQuery->groupBy('tag.id'); $dbQuery->orderBy('LOWER(tag.name)')->asc(); - if ($suppliedFilter) + if ($suppliedFilter !== null) $dbQuery->limit(15); $rows = $dbQuery->get(); $tags = R::convertToBeans('tag', $rows);