diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js
index 98c0179d..f7a8f4d0 100644
--- a/public_html/media/js/core.js
+++ b/public_html/media/js/core.js
@@ -154,7 +154,7 @@ $(function()
event.preventDefault();
}
}).autocomplete({
- minLength: 0,
+ minLength: 1,
source: function(request, response)
{
var term = extractLast(request.term);
diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php
index 63e999dd..14a339d2 100644
--- a/src/Controllers/TagController.php
+++ b/src/Controllers/TagController.php
@@ -10,25 +10,26 @@ class TagController
$this->context->subTitle = 'tags';
PrivilegesHelper::confirmWithException(Privilege::ListTags);
+ $suppliedFilter = InputHelper::get('filter');
$dbQuery = R::$f->begin();
$dbQuery->select('tag.*, COUNT(1) AS count');
$dbQuery->from('tag');
$dbQuery->innerJoin('post_tag');
$dbQuery->on('tag.id = post_tag.tag_id');
- $dbQuery->groupBy('tag.id');
- $dbQuery->orderBy('LOWER(tag.name)')->asc();
- $rows = $dbQuery->get();
- $tags = R::convertToBeans('tag', $rows);
-
- $suppliedFilter = InputHelper::get('filter');
if ($suppliedFilter)
{
- $rows = array_filter($rows, function($row) use ($suppliedFilter)
- {
- return strpos(strtolower($row['name']), strtolower($suppliedFilter)) !== false;
- });
+ if (strlen($suppliedFilter) >= 3)
+ $suppliedFilter = '%' . $suppliedFilter;
+ $suppliedFilter .= '%';
+ $dbQuery->where('LOWER(tag.name) LIKE LOWER(?)')->put($suppliedFilter);
}
+ $dbQuery->groupBy('tag.id');
+ $dbQuery->orderBy('LOWER(tag.name)')->asc();
+ if ($suppliedFilter)
+ $dbQuery->limit(15);
+ $rows = $dbQuery->get();
+ $tags = R::convertToBeans('tag', $rows);
$tags = [];
$tagDistribution = [];