]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 578494: When doing a QuickSearch on a phrase, pass the phrase quoted
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Fri, 23 Jul 2010 01:50:20 +0000 (18:50 -0700)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Fri, 23 Jul 2010 01:50:20 +0000 (18:50 -0700)
to the fulltext engine, so that it knows it's a phrase.
r=LpSolit, a=mkanat

Bugzilla/DB.pm
Bugzilla/Search/Quicksearch.pm

index 92d4e0c11c84a808a7a84f0bc8900358a3ee83df..b04de792bc8feae542dddfb89913e76ab94797f6 100644 (file)
@@ -45,6 +45,7 @@ use Bugzilla::DB::Schema;
 
 use List::Util qw(max);
 use Storable qw(dclone);
+use Text::ParseWords qw(shellwords);
 
 #####################################################################
 # Constants
@@ -362,8 +363,9 @@ sub sql_fulltext_search {
     # make the string lowercase to do case insensitive search
     my $lower_text = lc($text);
 
-    # split the text we search for into separate words
-    my @words = split(/\s+/, $lower_text);
+    # split the text we're searching for into separate words, understanding
+    # quotes.
+    my @words = shellwords($lower_text);
 
     # surround the words with wildcards and SQL quotes so we can use them
     # in LIKE search clauses
index 8a1219201a4c420bfa4b52f10f834f4f4c8b790f..1ac99308b5ae323fa8b702df00af0d187ea9caa1 100644 (file)
@@ -310,7 +310,7 @@ sub _handle_special_first_chars {
 
     if ($firstChar eq '#') {
         addChart('short_desc', 'substring', $baseWord, $negate);
-        addChart('content', 'matches', $baseWord, $negate);
+        addChart('content', 'matches', _matches_phrase($baseWord), $negate);
         return 1;
     }
     if ($firstChar eq ':') {
@@ -488,7 +488,7 @@ sub _default_quicksearch_word {
     addChart('alias', 'substring', $word, $negate);
     addChart('short_desc', 'substring', $word, $negate);
     addChart('status_whiteboard', 'substring', $word, $negate);
-    addChart('content', 'matches', $word, $negate);
+    addChart('content', 'matches', _matches_phrase($word), $negate);
 }
 
 sub _handle_urls {
@@ -540,6 +540,13 @@ sub splitString {
     return @parts;
 }
 
+# Quote and escape a phrase appropriately for a "content matches" search.
+sub _matches_phrase {
+    my ($phrase) = @_;
+    $phrase =~ s/"/\\"/g;
+    return "\"$phrase\"";
+}
+
 # Expand found prefixes to states or resolutions
 sub matchPrefixes {
     my $hr_states = shift;