]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 446645: Properly escape and understand hyphenated words in fulltext searches...
authormkanat%bugzilla.org <>
Thu, 7 Aug 2008 04:43:54 +0000 (04:43 +0000)
committermkanat%bugzilla.org <>
Thu, 7 Aug 2008 04:43:54 +0000 (04:43 +0000)
Patch By Jesse Clark <jjclark1982@gmail.com> r=mkanat, a=mkanat

Bugzilla/DB/Mysql.pm

index fdb47507870634a6279ee9d3ac7ea0d5cc003523..43646d8de0539815708f85266bee76fdbe69673f 100644 (file)
@@ -49,6 +49,7 @@ use Bugzilla::Error;
 use Bugzilla::DB::Schema::Mysql;
 
 use List::Util qw(max);
+use Text::ParseWords;
 
 # This module extends the DB interface via inheritance
 use base qw(Bugzilla::DB);
@@ -141,8 +142,21 @@ sub sql_fulltext_search {
     my ($self, $column, $text) = @_;
 
     # Add the boolean mode modifier if the search string contains
-    # boolean operators.
-    my $mode = ($text =~ /[+-<>()~*"]/ ? "IN BOOLEAN MODE" : "");
+    # boolean operators at the start or end of a word.
+    my $mode = '';
+    if ($text =~ /(?:^|\W)[+\-<>~"()]/ || $text =~ /[()"*](?:$|\W)/) {
+        $mode = 'IN BOOLEAN MODE';
+
+        # quote un-quoted compound words
+        my @words = quotewords('[\s()]+', 'delimiter', $text);
+        foreach my $word (@words) {
+            # match words that have word chars, non-word chars, and no quotes
+            if ($word =~ /\w/ && $word =~ m/\W/ && $word !~ m/"/) {
+                $word = '"' . $word . '"';
+            }
+        }
+        $text = join('', @words);
+    }
 
     # quote the text for use in the MATCH AGAINST expression
     $text = $self->quote($text);