From: mkanat%bugzilla.org <> Date: Tue, 28 Apr 2009 20:14:24 +0000 (+0000) Subject: Bug 474897: Give Bug.search sensible default search types for its fields X-Git-Tag: bugzilla-3.4rc1~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d9e4844cfe17142c4f0fbad63ccae0e37c3a447;p=thirdparty%2Fbugzilla.git Bug 474897: Give Bug.search sensible default search types for its fields Patch by Max Kanat-Alexander r=ghendricks, a=mkanat --- diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index b91576ca5e..b24e9b69df 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -170,14 +170,16 @@ sub match { elsif ( $field eq 'WHERE' ) { # the WHERE value is a hashref where the keys are # "column_name operator ?" and values are the placeholder's - # value. - foreach my $k (keys( %$value )) { - push( @terms, $k ); - push( @values, $value->{$k} ); + # value (either a scalar or an array of values). + foreach my $k (keys %$value) { + push(@terms, $k); + my @this_value = ref($value->{$k}) ? @{ $value->{$k} } + : ($value->{$k}); + push(@values, @this_value); } next; } - + if (ref $value eq 'ARRAY') { # IN () is invalid SQL, and if we have an empty list # to match against, we're just returning an empty diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index f76d800fa3..0a22ffb1a6 100755 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -246,12 +246,27 @@ sub search { $params = _map_fields($params); - # If the user set the 'last_change_time' param (translated into delta_ts - # by the field map), use a custom WHERE to constrain the query to only - # those bugs that have a delta_ts greater than or equal to - # the specified time. + # Do special search types for certain fields. if ( my $bug_when = delete $params->{delta_ts} ) { - $params->{WHERE} = {'delta_ts >= ?' => $bug_when}; + $params->{WHERE}->{'delta_ts >= ?'} = $bug_when; + } + if (my $when = delete $params->{creation_ts}) { + $params->{WHERE}->{'creation_ts >= ?'} = $when; + } + if (my $votes = delete $params->{votes}) { + $params->{WHERE}->{'votes >= ?'} = $votes; + } + if (my $summary = delete $params->{short_desc}) { + my @strings = ref $summary ? @$summary : ($summary); + my @likes = ("short_desc LIKE ?") x @strings; + my $clause = join(' OR ', @likes); + $params->{WHERE}->{"($clause)"} = [map { "\%$_\%" } @strings]; + } + if (my $whiteboard = delete $params->{status_whiteboard}) { + my @strings = ref $whiteboard ? @$whiteboard : ($whiteboard); + my @likes = ("status_whiteboard LIKE ?") x @strings; + my $clause = join(' OR ', @likes); + $params->{WHERE}->{"($clause)"} = [map { "\%$_\%" } @strings]; } my $bugs = Bugzilla::Bug->match($params); @@ -994,10 +1009,11 @@ Allows you to search for bugs based on particular criteria. =item B -Bugs are returned if they match I the criteria you specify -in these parameters. That is, we don't match against -substrings--if a bug is in the "Widgets" product and you ask for bugs in -the "Widg" product, you won't get anything. +Unless otherwise specified in the description of a parameter, bugs are +returned if they match I the criteria you specify in these +parameters. That is, we don't match against substrings--if a bug is in +the "Widgets" product and you ask for bugs in the "Widg" product, you +won't get anything. Criteria are joined in a logical AND. That is, you will be returned bugs that match I of the criteria, not bugs that match I of @@ -1010,9 +1026,6 @@ the "Foo" or "Bar" products, you'd pass: product => ['Foo', 'Bar'] -Fields below only have descriptions if it's not clear what bug field -they match up to, or if they have some special behavior. - Some Bugzillas may treat your arguments case-sensitively, depending on what database system they are using. Most commonly, though, Bugzilla is not case-sensitive with the arguments passed (because MySQL is the @@ -1039,7 +1052,8 @@ don't want this, be sure to also specify the C argument. =item C -C When the bug was created. +C Searches for bugs that were created at this time or later. +May not be an array. =item C @@ -1047,10 +1061,8 @@ C The numeric id of the bug. =item C -C Limit the search to only those bugs which have changed -in some way since the specified time. It includes all bugs changed -between the specified time and the present. Note: only a single -C will accepted, not an array. +C Searches for bugs that were modified at this time or later. +May not be an array. =item C @@ -1099,9 +1111,14 @@ if it has one, which is a separate field above). =item C -C The single-line summary field of a bug. (This isn't very -useful to search on, since we don't do substring matches, only exact -matches.) +C Searches for substrings in the single-line Summary field on +bugs. If you specify an array, then bugs whose summaries match I of the +passed substrings will be returned. + +Note that unlike searching in the Bugzilla UI, substrings are not split +on spaces. So searching for C will match "This is a foo bar" +but not "This foo is a bar". C<['foo', 'bar']>, would, however, match +the second item. =item C @@ -1128,11 +1145,14 @@ C The Version field of a bug. =item C -C How many votes this bug has, total. +C Searches for bugs with this many votes or greater. May not +be an array. =item C -C The "Status Whiteboard" field of a bug. +C Search the "Status Whiteboard" field on bugs for a substring. +Works the same as the C field described above, but searches the +Status Whiteboard field. =back