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

search: Only promote to wildcard search if query ends in a word char

Otherwise we might end up with a search term like '"some junk"*' which is
invalid.
parent 0916c7ab
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@ class OrgsAjaxAPI extends AjaxController {
$orgs->order_by(new SqlCode('__relevance__'), QuerySet::DESC)
->distinct('id');
if (!count($orgs) && substr($q, strlen($q)-1) != '*') {
if (!count($orgs) && preg_match('`\w$`u', $q)) {
// Do wildcard full-text search
$_REQUEST['q'] = $q."*";
return $this->search($type);
......
......@@ -66,7 +66,7 @@ class TicketsAjaxAPI extends AjaxController {
->limit($limit)
->union($hits);
}
elseif (!count($hits) && $q[strlen($q)-1] != '*') {
elseif (!count($hits) && preg_match('`\w$`u', $q)) {
// Do wild-card fulltext search
$_REQUEST['q'] = $q.'*';
return $this->lookup();
......
......@@ -55,7 +55,7 @@ class UsersAjaxAPI extends AjaxController {
$users->order_by(new SqlCode('__relevance__'), QuerySet::DESC)
->distinct('id');
if (!count($emails) && !count($users) && substr($q, strlen($q)-1) != '*') {
if (!count($emails) && !count($users) && preg_match('`\w$`u', $q)) {
// Do wildcard full-text search
$_REQUEST['q'] = $q."*";
return $this->search($type);
......
......@@ -94,11 +94,12 @@ case 'search':
}
}
elseif ($_REQUEST['query']) {
$q = trim($_REQUEST['query']);
// [Search] click, consider keywords
$__tickets = $ost->searcher->find($_REQUEST['query'], $tickets);
if (!count($__tickets)) {
$__tickets = $ost->searcher->find($q, $tickets);
if (!count($__tickets) && preg_match('`\w$`u', $q)) {
// Do wildcard search if no hits
$__tickets = $ost->searcher->find($_REQUEST['query'].'*', $tickets);
$__tickets = $ost->searcher->find($q.'*', $tickets);
}
$tickets = $__tickets;
$has_relevance = true;
......
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