From: Max Kanat-Alexander Date: Tue, 15 Feb 2011 05:44:32 +0000 (-0800) Subject: Bug 490322: Make "allwords" work with the keywords field, again. X-Git-Tag: bugzilla-4.0~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46096a31fa1b620beb16b20b1763136ca4962cdc;p=thirdparty%2Fbugzilla.git Bug 490322: Make "allwords" work with the keywords field, again. r=glob, a=mkanat --- diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm index a06dcb4419..025c11e8c9 100644 --- a/Bugzilla/Search.pm +++ b/Bugzilla/Search.pm @@ -2089,33 +2089,26 @@ sub _keywords_exact { my ($chartid, $v, $ff, $f, $t, $term, $supptables) = @func_args{qw(chartid v ff f t term supptables)}; - my @list; + my @keyword_ids; + foreach my $word (split(/[\s,]+/, $$v)) { + next if $word eq ''; + my $keyword = Bugzilla::Keyword->check($word); + push(@keyword_ids, $keyword->id); + } + my $table = "keywords_$$chartid"; - foreach my $value (split(/[\s,]+/, $$v)) { - if ($value eq '') { - next; - } - my $keyword = new Bugzilla::Keyword({name => $value}); - if ($keyword) { - push(@list, "$table.keywordid = " . $keyword->id); - } - else { - ThrowUserError("unknown_keyword", - { keyword => $$v }); - } + my $id_field = "$table.keywordid"; + if ($$t eq 'anywords' or $$t eq 'anyexact') { + my $dbh = Bugzilla->dbh; + $$term = $dbh->sql_in($id_field, \@keyword_ids); } - my $haveawordterm; - if (@list) { - $haveawordterm = "(" . join(' OR ', @list) . ")"; - if ($$t eq "anywords") { - $$term = $haveawordterm; - } elsif ($$t eq "allwords") { - $self->_allwords; - if ($$term && $haveawordterm) { - $$term = "(($$term) AND $haveawordterm)"; - } - } + if ($$t eq 'allwords') { + my @terms = + map { "bugs.bug_id IN (SELECT bug_id FROM keywords WHERE keywordid = $_)" } @keyword_ids; + $$term = join(' AND ', @terms); + return; } + if ($$term) { push(@$supptables, "LEFT JOIN keywords AS $table " . "ON $table.bug_id = bugs.bug_id"); diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index bd9fb0a5b1..f2cf053a52 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -1788,6 +1788,8 @@ field [% ELSIF class == "Bugzilla::Group" %] group + [% ELSIF class == "Bugzilla::Keyword" %] + keyword [% ELSIF class == "Bugzilla::Product" %] product [% ELSIF class == "Bugzilla::Search::Recent" %] diff --git a/xt/lib/Bugzilla/Test/Search/Constants.pm b/xt/lib/Bugzilla/Test/Search/Constants.pm index 7fe7d0efa4..01a27a9312 100644 --- a/xt/lib/Bugzilla/Test/Search/Constants.pm +++ b/xt/lib/Bugzilla/Test/Search/Constants.pm @@ -291,7 +291,6 @@ use constant ALLWORDS_BROKEN => ( ATTACHMENT_BOOLEANS_SEARCH_BROKEN, bug_group => { contains => [1] }, cc => { contains => [1] }, - keywords => { contains => [1] }, longdesc => { contains => [1] }, work_time => { contains => [1] }, percentage_complete => { contains => [2,3,4,5] }, @@ -428,7 +427,10 @@ use constant KNOWN_BROKEN => { bug_group => { contains => [3,4,5] }, }, - 'allwordssubstr-<1>' => { ALLWORDS_BROKEN }, + 'allwordssubstr-<1>' => { + ALLWORDS_BROKEN, + keywords => { contains => [1] } + }, 'allwordssubstr-<1>,<2>' => { ATTACHMENT_BOOLEANS_SEARCH_BROKEN, percentage_complete => { contains => [1,2,3,4,5] },