diff --git a/include/ajax.orgs.php b/include/ajax.orgs.php index 202d2d8f095d8739d0b1ebb6ea2bc85c08dcd6d6..0cf4f22d6ad391afff7543079da762f14113b314 100644 --- a/include/ajax.orgs.php +++ b/include/ajax.orgs.php @@ -29,6 +29,9 @@ class OrgsAjaxAPI extends AjaxController { $q = $_REQUEST['q']; $limit = isset($_REQUEST['limit']) ? (int) $_REQUEST['limit']:25; + if (strlen($q) < 2) + return $this->encode(array()); + $orgs = Organization::objects() ->values_flat('id', 'name') ->limit($limit); diff --git a/include/ajax.tickets.php b/include/ajax.tickets.php index 9a5822e123797a77313f52cccd9426580dcfbaac..35bb513e973f3991c3dc729e4b19f4926f33ab39 100644 --- a/include/ajax.tickets.php +++ b/include/ajax.tickets.php @@ -47,8 +47,9 @@ class TicketsAjaxAPI extends AjaxController { ->limit($limit); $q = $_REQUEST['q']; - // Drop at sign in email addresses - $q = str_replace('@', ' ', $q); + + if (strlen($q) < 2) + return $this->encode(array()); global $ost; $hits = $ost->searcher->find($q, $hits) diff --git a/include/ajax.users.php b/include/ajax.users.php index 03e203000594973768e7dd5c29f9e8d55982841d..bb94a1528992b9fb991d3f3e399de5dcefcd8bdb 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -34,6 +34,9 @@ class UsersAjaxAPI extends AjaxController { $users=array(); $emails=array(); + if (strlen($q) < 2) + return $this->encode(array()); + if (!$type || !strcasecmp($type, 'remote')) { foreach (AuthenticationBackend::searchUsers($q) as $u) { $name = new UsersName(array('first' => $u['first'], 'last' => $u['last'])); diff --git a/include/class.search.php b/include/class.search.php index e4106eaee1ea2351ea14bf228263cb57369e8a0a..474fa3132d6c6763149c49c74893602c829fe26c 100644 --- a/include/class.search.php +++ b/include/class.search.php @@ -327,6 +327,11 @@ class MysqlSearchBackend extends SearchBackend { function find($query, QuerySet $criteria, $addRelevance=true) { global $thisstaff; + // MySQL usually doesn't handle words shorter than three letters + // (except with special configuration) + if (strlen($query) < 3) + return $criteria; + $criteria = clone $criteria; $mode = ' IN NATURAL LANGUAGE MODE'; diff --git a/include/client/tickets.inc.php b/include/client/tickets.inc.php index cf3c5e1d92d1c83fd9b02a9bea18bc12f7e3470e..f37874b55a8916081c924599130f64c863d36f37 100644 --- a/include/client/tickets.inc.php +++ b/include/client/tickets.inc.php @@ -90,10 +90,10 @@ if ($thisclient->canSeeOrgTickets()) { // Perform basic search if ($settings['keywords']) { - $q = $settings['keywords']; + $q = trim($settings['keywords']); if (is_numeric($q)) { $tickets->filter(array('number__startswith'=>$q)); - } else { //Deep search! + } elseif (strlen($q) > 2) { //Deep search! // Use the search engine to perform the search $tickets = $ost->searcher->find($q, $tickets); } diff --git a/include/staff/tickets.inc.php b/include/staff/tickets.inc.php index a3701e627a0994bd40fce7b3e1c336fba5862a94..929e27edabd09f2d636c9b8f3ef4885383e66445 100644 --- a/include/staff/tickets.inc.php +++ b/include/staff/tickets.inc.php @@ -93,8 +93,10 @@ case 'search': )); } } - elseif ($_REQUEST['query']) { - $q = trim($_REQUEST['query']); + elseif (isset($_REQUEST['query']) + && ($q = trim($_REQUEST['query'])) + && strlen($q) > 2 + ) { // [Search] click, consider keywords $__tickets = $ost->searcher->find($q, $tickets); if (!count($__tickets) && preg_match('`\w$`u', $q)) {