Fixed tag autocompletion

It yielded too many results in some cases.
This commit is contained in:
Marcin Kurczewski 2013-10-27 23:14:48 +01:00
parent e346a8e57c
commit 24f5024db3
2 changed files with 7 additions and 6 deletions

View file

@ -158,10 +158,11 @@ $(function()
source: function(request, response) source: function(request, response)
{ {
var term = extractLast(request.term); var term = extractLast(request.term);
$.get(searchInput.attr('data-autocomplete-url') + '?json', {filter: term}, function(data) if (term != '')
{ $.get(searchInput.attr('data-autocomplete-url') + '?json', {filter: term}, function(data)
response($.map(data.tags, function(tag) { return { label: tag, value: tag }; })); {
}); response($.map(data.tags, function(tag) { return { label: tag, value: tag }; }));
});
}, },
focus: function() focus: function()
{ {

View file

@ -17,7 +17,7 @@ class TagController
$dbQuery->from('tag'); $dbQuery->from('tag');
$dbQuery->innerJoin('post_tag'); $dbQuery->innerJoin('post_tag');
$dbQuery->on('tag.id = post_tag.tag_id'); $dbQuery->on('tag.id = post_tag.tag_id');
if ($suppliedFilter) if ($suppliedFilter !== null)
{ {
if (strlen($suppliedFilter) >= 3) if (strlen($suppliedFilter) >= 3)
$suppliedFilter = '%' . $suppliedFilter; $suppliedFilter = '%' . $suppliedFilter;
@ -26,7 +26,7 @@ class TagController
} }
$dbQuery->groupBy('tag.id'); $dbQuery->groupBy('tag.id');
$dbQuery->orderBy('LOWER(tag.name)')->asc(); $dbQuery->orderBy('LOWER(tag.name)')->asc();
if ($suppliedFilter) if ($suppliedFilter !== null)
$dbQuery->limit(15); $dbQuery->limit(15);
$rows = $dbQuery->get(); $rows = $dbQuery->get();
$tags = R::convertToBeans('tag', $rows); $tags = R::convertToBeans('tag', $rows);