From 7b29289e910d51705b49249821f9b1f321806473 Mon Sep 17 00:00:00 2001 From: Peter Rotich <peter@osticket.com> Date: Wed, 14 Oct 2015 06:29:01 +0000 Subject: [PATCH] Make fulltext search optional on user lookup Fulltext search is not ideal for user lookup. This pull request makes the fulltext based search optional and disabled by default. Add space when indexing user's custom data and emails. --- include/ajax.users.php | 28 ++++++++++++++++++---------- include/class.search.php | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/ajax.users.php b/include/ajax.users.php index dba3cb1da..6d1f5936b 100644 --- a/include/ajax.users.php +++ b/include/ajax.users.php @@ -22,8 +22,8 @@ require_once INCLUDE_DIR.'class.note.php'; class UsersAjaxAPI extends AjaxController { - /* Assumes search by emal for now */ - function search($type = null) { + /* Assumes search by basic info for now */ + function search($type = null, $fulltext=false) { if(!isset($_REQUEST['q'])) { Http::response(400, __('Query argument is required')); @@ -53,15 +53,23 @@ class UsersAjaxAPI extends AjaxController { ->values_flat('id', 'emails__address', 'name') ->limit($limit); - global $ost; - $users = $ost->searcher->find($q, $users); - $users->order_by(new SqlCode('__relevance__'), QuerySet::DESC) - ->distinct('id'); + if ($fulltext) { + global $ost; + $users = $ost->searcher->find($q, $users); + $users->order_by(new SqlCode('__relevance__'), QuerySet::DESC) + ->distinct('id'); - if (!count($emails) && !count($users) && preg_match('`\w$`u', $q)) { - // Do wildcard full-text search - $_REQUEST['q'] = $q."*"; - return $this->search($type); + if (!count($emails) && !count($users) && preg_match('`\w$`u', $q)) { + // Do wildcard full-text search + $_REQUEST['q'] = $q."*"; + return $this->search($type, $fulltext); + } + } else { + $users->filter(Q::any(array( + 'emails__address__contains' => $q, + 'name__contains' => $q, + 'org__name__contains' => $q, + ))); } if ($emails = array_filter($emails)) { diff --git a/include/class.search.php b/include/class.search.php index 474fa3132..fb4c4e800 100644 --- a/include/class.search.php +++ b/include/class.search.php @@ -266,7 +266,7 @@ class MysqlSearchBackend extends SearchBackend { if ($model instanceof Ticket) $attrs['title'] = $attrs['number'].' '.$attrs['title']; elseif ($model instanceof User) - $content .= implode("\n", $attrs['emails']); + $content .=' '.implode("\n", $attrs['emails']); $title = $attrs['title'] ?: ''; -- GitLab