Skip to content

Commit

Permalink
Search both subject and description in simple search
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnavy committed Dec 3, 2024
1 parent f06edd0 commit 71d12cf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
11 changes: 8 additions & 3 deletions lib/RT/Search/Simple.pm
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ sub QueryToSQL {
next unless @{$limits{$subclause}};

my $op = $AND{lc $subclause} ? "AND" : "OR";
push @clauses, "( ".join(" $op ", @{$limits{$subclause}})." )";
if ( @{$limits{$subclause}} == 1 && $limits{$subclause}[0] =~ /^\(.+\)$/) {
push @clauses, @{$limits{$subclause}};
}
else {
push @clauses, "( ".join(" $op ", @{$limits{$subclause}})." )";
}
}

return join " AND ", @clauses;
Expand Down Expand Up @@ -280,9 +285,9 @@ sub GuessType {
sub HandleDefault {
my $fts = RT->Config->Get('FullTextSearch');
if ($fts->{Enable} and $fts->{Indexed}) {
return default => "(Subject LIKE '$_[1]' OR Content LIKE '$_[1]')";
return default => "( Subject LIKE '$_[1]' OR Description LIKE '$_[1]' OR Content LIKE '$_[1]' )";
} else {
return default => "Subject LIKE '$_[1]'";
return default => "( Subject LIKE '$_[1]' OR Description LIKE '$_[1]' )";
}
}
sub HandleSubject { return subject => "Subject LIKE '$_[1]'"; }
Expand Down
4 changes: 2 additions & 2 deletions share/html/Search/Simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@

% my @strong = qw(<strong> </strong>);

<p><&|/l_unsafe, @strong &>Search for tickets by entering [_1]id[_2] numbers, subject words [_1]"in quotes"[_2], [_1]queues[_2] by name, Owners by [_1]username[_2], Requestors by [_1]email address[_2], and ticket [_1]statuses[_2]. Searching for [_1]@domainname.com[_2] will return tickets with requestors from that domain.</&></p>
<p><&|/l_unsafe, @strong &>Search for tickets by entering [_1]id[_2] numbers, subject/description words [_1]"in quotes"[_2], [_1]queues[_2] by name, Owners by [_1]username[_2], Requestors by [_1]email address[_2], and ticket [_1]statuses[_2]. Searching for [_1]@domainname.com[_2] will return tickets with requestors from that domain.</&></p>

<p><&|/l&>Any word not recognized by RT is searched for in ticket subjects.</&></p>
<p><&|/l&>Any word not recognized by RT is searched for in ticket subjects and descriptions.</&></p>

% my $config = RT->Config->Get('FullTextSearch') || {};
% my $fulltext_keyword = 'fulltext:';
Expand Down
20 changes: 10 additions & 10 deletions t/web/simple_search.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@ my $root = RT::Test->load_or_create_user( Name => 'root' );
TicketsObj => $tickets,
Argument => '',
);
is $parser->QueryToSQL("foo"), "( (Subject LIKE 'foo' OR Description LIKE 'foo') ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("1 foo"), "( (Subject LIKE 'foo' OR Description LIKE 'foo') AND (Subject LIKE '1' OR Description LIKE '1') ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("foo"), "( Subject LIKE 'foo' OR Description LIKE 'foo' ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("1 foo"), "( ( Subject LIKE 'foo' OR Description LIKE 'foo' ) AND ( Subject LIKE '1' OR Description LIKE '1' ) ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("1"), "( Id = 1 )", "correct parsing";
is $parser->QueryToSQL("#1"), "( Id = 1 )", "correct parsing";
is $parser->QueryToSQL("'1'"), "( (Subject LIKE '1' OR Description LIKE '1') ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("'1'"), "( Subject LIKE '1' OR Description LIKE '1' ) AND ( Status = '__Active__' )", "correct parsing";

is $parser->QueryToSQL("foo bar"),
"( (Subject LIKE 'foo' OR Description LIKE 'foo') AND (Subject LIKE 'bar' OR Description LIKE 'bar') ) AND ( Status = '__Active__' )",
"( ( Subject LIKE 'foo' OR Description LIKE 'foo' ) AND ( Subject LIKE 'bar' OR Description LIKE 'bar' ) ) AND ( Status = '__Active__' )",
"correct parsing";
is $parser->QueryToSQL("'foo bar'"),
"( (Subject LIKE 'foo bar' OR Description LIKE 'foo bar') ) AND ( Status = '__Active__' )",
"( Subject LIKE 'foo bar' OR Description LIKE 'foo bar' ) AND ( Status = '__Active__' )",
"correct parsing";

is $parser->QueryToSQL("'foo \\' bar'"),
"( (Subject LIKE 'foo \\' bar' OR Description LIKE 'foo \\' bar') ) AND ( Status = '__Active__' )",
"( Subject LIKE 'foo \\' bar' OR Description LIKE 'foo \\' bar' ) AND ( Status = '__Active__' )",
"correct parsing";
is $parser->QueryToSQL('"foo \' bar"'),
"( (Subject LIKE 'foo \\' bar' OR Description LIKE 'foo \\' bar') ) AND ( Status = '__Active__' )",
"( Subject LIKE 'foo \\' bar' OR Description LIKE 'foo \\' bar' ) AND ( Status = '__Active__' )",
"correct parsing";
is $parser->QueryToSQL('"\f\o\o"'),
"( (Subject LIKE '\\\\f\\\\o\\\\o' OR Description LIKE '\\\\f\\\\o\\\\o') ) AND ( Status = '__Active__' )",
"( Subject LIKE '\\\\f\\\\o\\\\o' OR Description LIKE '\\\\f\\\\o\\\\o' ) AND ( Status = '__Active__' )",
"correct parsing";

is $parser->QueryToSQL("General"), "( Queue = 'General' ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("'Two Words'"), "( (Subject LIKE 'Two Words' OR Description LIKE 'Two Words') ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("'Two Words'"), "( Subject LIKE 'Two Words' OR Description LIKE 'Two Words' ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("queue:'Two Words'"), "( Queue = 'Two Words' ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("subject:'Two Words'"), "( Status = '__Active__' ) AND ( Subject LIKE 'Two Words' )", "correct parsing";

is $parser->QueryToSQL("me"), "( Owner.id = '__CurrentUser__' ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("'me'"), "( (Subject LIKE 'me' OR Description LIKE 'me') ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("'me'"), "( Subject LIKE 'me' OR Description LIKE 'me' ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("owner:me"), "( Owner.id = '__CurrentUser__' ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL("owner:'me'"), "( Owner = 'me' ) AND ( Status = '__Active__' )", "correct parsing";
is $parser->QueryToSQL('owner:root@localhost'), "( Owner.EmailAddress = 'root\@localhost' ) AND ( Status = '__Active__' )", "Email address as owner";
Expand Down

0 comments on commit 71d12cf

Please sign in to comment.