Skip to content
Snippets Groups Projects
Commit 5ee43e7d authored by Jared Hancock's avatar Jared Hancock
Browse files

search: Avoid searching for very short terms

parent 99dbd4ab
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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)
......
......@@ -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']));
......
......@@ -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';
......
......@@ -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);
}
......
......@@ -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)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment