]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1531757 - Allow to search only in bug description (comment 0) with both Quick...
authorKohei Yoshino <kohei.yoshino@gmail.com>
Tue, 2 Apr 2019 19:27:45 +0000 (15:27 -0400)
committerGitHub <noreply@github.com>
Tue, 2 Apr 2019 19:27:45 +0000 (15:27 -0400)
Bugzilla/Search.pm
Bugzilla/Search/Quicksearch.pm
Bugzilla/WebService/Bug.pm
docs/en/rst/api/core/v1/bug.rst
template/en/default/pages/quicksearch.html.tmpl
template/en/default/search/form.html.tmpl

index c61f448e752b0b360f0be02cd4ed734094d827ab..a3f92901125b658e142b604fcdd327b96729a690 100644 (file)
@@ -2667,6 +2667,12 @@ sub _long_desc_nonchanged {
   };
   $self->_do_operator_function($join_args);
 
+  # Allow to search only in bug description (initial comment)
+  if ($self->_params->{longdesc_initial}) {
+    $join_args->{term}
+      .= ($join_args->{term} ? " AND " : "") . "$table.bug_when = bugs.creation_ts";
+  }
+
   # If the user is not part of the insiders group, they cannot see
   # private comments
   if (!$self->_user->is_insider) {
index c8317a1006807edcdfe4e95a51b67e11aba5a61d..335caedbbcf87ac142fcad6930b718841db11c95 100644 (file)
@@ -131,7 +131,8 @@ use constant COMPONENT_EXCEPTIONS => (
 );
 
 # Quicksearch-wide globals for boolean charts.
-our ($chart, $and, $or, $fulltext, $bug_status_set, $bug_product_set, $ELASTIC);
+our ($chart, $and, $or, $longdesc_initial, $fulltext, $bug_status_set,
+     $bug_product_set, $ELASTIC);
 
 sub quicksearch {
   my ($searchstring) = (@_);
@@ -199,6 +200,12 @@ sub quicksearch {
         unshift(@words, "-$word");
       }
 
+      # --description and ++description disable or enable description searching
+      elsif ($word =~ /^(--|\+\+)description?$/i) {
+        $longdesc_initial = $1 eq '--' ? 0 : 1;
+        $cgi->param('longdesc_initial', $longdesc_initial);
+      }
+
       # --comment and ++comment disable or enable fulltext searching
       elsif ($word =~ /^(--|\+\+)comments?$/i) {
         $fulltext = $1 eq '--' ? 0 : 1;
@@ -410,6 +417,8 @@ sub _handle_special_first_chars {
 
   if ($firstChar eq '#') {
     addChart('short_desc', 'substring', $baseWord, $negate);
+    addChart('longdesc',   'substring', $baseWord, $negate)
+      if $longdesc_initial;
     addChart('content', 'matches', _matches_phrase($baseWord), $negate)
       if $fulltext;
     return 1;
@@ -628,7 +637,8 @@ sub _default_quicksearch_word {
   addChart('alias',             'substring', $word, $negate);
   addChart('short_desc',        'substring', $word, $negate);
   addChart('status_whiteboard', 'substring', $word, $negate);
-  addChart('longdesc',          'substring', $word, $negate) if $ELASTIC;
+  addChart('longdesc',          'substring', $word, $negate)
+    if $longdesc_initial || $ELASTIC;
   addChart('content', 'matches', _matches_phrase($word), $negate)
     if $fulltext && !$ELASTIC;
 
index bbfbe6360bf2f144f11bc96517d9499dce260cdf..cae4efde7e844dcbe3aa8efc19d215f69b18b97a 100644 (file)
@@ -551,6 +551,12 @@ sub search {
     delete $match_params->{offset};
   }
 
+  # Allow to search only in bug description (initial comment)
+  if (defined $match_params->{description}) {
+    $match_params->{longdesc} = delete $match_params->{description};
+    $match_params->{longdesc_initial} = 1;
+  }
+
   $match_params = Bugzilla::Bug::map_fields($match_params);
 
   my %options = (fields => ['bug_id']);
@@ -1475,6 +1481,12 @@ sub _bug_to_hash {
     my @depends_on = map { $self->type('int', $_) } @{$bug->dependson};
     $item{'depends_on'} = \@depends_on;
   }
+  if (filter_wants $params, 'description', ['extra']) {
+    my $comment = Bugzilla::Comment->match({bug_id => $bug->id, LIMIT => 1})->[0];
+    $item{'description'}
+      = ($comment && (!$comment->is_private || Bugzilla->user->is_insider))
+      ? $comment->body : '';
+  }
   if (filter_wants $params, 'dupe_of') {
     $item{'dupe_of'} = $self->type('int', $bug->dup_id);
   }
@@ -2766,6 +2778,13 @@ in the return value.
 
 C<array> of C<int>s. The ids of bugs that this bug "depends on".
 
+=item C<description>
+
+C<string> The description (initial comment) of the bug.
+
+This is an B<extra> field returned only by specifying C<description> or
+C<_extra> in C<include_fields>.
+
 =item C<dupe_of>
 
 C<int> The bug ID of the bug that this bug is a duplicate of. If this bug
@@ -3132,9 +3151,9 @@ and all custom fields.
 =item The C<actual_time> item was added to the C<bugs> return value
 in Bugzilla B<4.4>.
 
-=item The C<attachments>, C<comments>, C<duplicates>, C<history>,
-C<regressed_by>, C<regressions>, C<triage_owner> and C<type> fields were added
-in Bugzilla B<6.0>.
+=item The C<attachments>, C<comments>, C<description>, C<duplicates>,
+C<history>, C<regressed_by>, C<regressions>, C<triage_owner> and C<type> fields
+were added in Bugzilla B<6.0>.
 
 =back
 
@@ -3401,6 +3420,10 @@ C<string> The login name of the user who created the bug.
 You can also pass this argument with the name C<reporter>, for
 backwards compatibility with older Bugzillas.
 
+=item C<description>
+
+C<string> The description (initial comment) of the bug.
+
 =item C<id>
 
 C<int> The numeric id of the bug.
@@ -3557,6 +3580,8 @@ in Bugzilla B<5.0>.
 
 =item Updated to allow quicksearch capability in Bugzilla B<5.0>.
 
+=item The C<description> field was added in Bugzilla B<6.0>.
+
 =back
 
 =back
@@ -3625,8 +3650,8 @@ filed.
 =item C<version> (string) B<Required> - A version of the product above;
 the version the bug was found in.
 
-=item C<description> (string) B<Defaulted> - The initial description for
-this bug. Some Bugzilla installations require this to not be blank.
+=item C<description> (string) B<Defaulted> - The description (initial comment)
+of the bug. Some Bugzilla installations require this to not be blank.
 
 =item C<op_sys> (string) B<Defaulted> - The operating system the bug was
 discovered on.
index cead3697eab7d8a1fe70812295671d2ffbd83d7d..6fe94ddcfa74b1d54a336a73dc8b9fa16c6158d0 100644 (file)
@@ -256,6 +256,7 @@ attachments          array   Each array item is an Attachment object. See
                              :ref:`rest_attachments` for details of the object.
 comments             array   Each array item is a Comment object. See
                              :ref:`rest_comments` for details of the object.
+description          string  The description (initial comment) of the bug.
 history              array   Each array item is a History object. See
                              :ref:`rest_history` for details of the object.
 tags                 array   Each array item is a tag name. Note that tags are
@@ -497,6 +498,7 @@ creator           string    The login name of the user who created the bug. You
                             can also pass this argument with the name
                             ``reporter``, for backwards compatibility with
                             older Bugzillas.
+description       string    The description (initial comment) of the bug.
 id                int       The numeric ID of the bug.
 last_change_time  datetime  Searches for bugs that were modified at this time
                             or later. May not be an array.
@@ -635,9 +637,9 @@ name                type     description
 **summary**         string   A brief description of the bug being filed.
 **version**         string   A version of the product above; the version the
                              bug was found in.
-description         string   (defaulted) The initial description for this bug.
-                             Some Bugzilla installations require this to not be
-                             blank.
+description         string   (defaulted) The description (initial comment) of the
+                             bug. Some Bugzilla installations require this to not
+                             be blank.
 op_sys              string   (defaulted) The operating system the bug was
                              discovered on.
 platform            string   (defaulted) What type of hardware the bug was
index 38fb9c00401978948e16e2a6b8a269addde8bfe8..d5417e761d0d85175e3d0ccf736d3d23f58d735c 100644 (file)
       <td class="field_name">Comment Searching</td>
       <td class="field_nickname">
         Allows overriding of the comment searching preference.<br>
-        "<strong>++comments</strong>" will always enable comment searching.<br>
-        "<strong>--comments</strong>" will always disable searching.<br>
+        "<strong>++comments</strong>" enables full-text search (all comments, slow)<br>
+        "<strong>--comments</strong>" disables full-text search<br>
+        "<strong>++description</strong>" enables description search (initial comment only)<br>
+        "<strong>--description</strong>" disables description search<br>
       </td>
     </tr>
     [% IF Param('usestatuswhiteboard') %]
index 54d297d50da6f8948054da480cca8066d8443665..33c6f1f2317ba0e21a71496c037c347fa332168d 100644 (file)
@@ -233,6 +233,10 @@ TUI_hide_default('information_query');
           value => default.${field_container.field.name}.0
           type_selected => default.$type.0
       %]
+      [% IF field_container.field.name == 'longdesc' %]
+        <label><input type="checkbox" name="longdesc_initial" value="1"
+          [%- " checked" IF default.longdesc_initial.0 == "1" %]> Description (initial comment) only</label>
+      [% END %]
     </div>
   [% END %]