Commit 18d0e31a authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 446645: Properly escape and understand hyphenated words in fulltext searches when using MySQL

Patch By Jesse Clark <jjclark1982@gmail.com> r=mkanat, a=mkanat
parent 70540fb1
...@@ -49,6 +49,7 @@ use Bugzilla::Error; ...@@ -49,6 +49,7 @@ use Bugzilla::Error;
use Bugzilla::DB::Schema::Mysql; use Bugzilla::DB::Schema::Mysql;
use List::Util qw(max); use List::Util qw(max);
use Text::ParseWords;
# This module extends the DB interface via inheritance # This module extends the DB interface via inheritance
use base qw(Bugzilla::DB); use base qw(Bugzilla::DB);
...@@ -141,8 +142,21 @@ sub sql_fulltext_search { ...@@ -141,8 +142,21 @@ sub sql_fulltext_search {
my ($self, $column, $text) = @_; my ($self, $column, $text) = @_;
# Add the boolean mode modifier if the search string contains # Add the boolean mode modifier if the search string contains
# boolean operators. # boolean operators at the start or end of a word.
my $mode = ($text =~ /[+-<>()~*"]/ ? "IN BOOLEAN MODE" : ""); 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 # quote the text for use in the MATCH AGAINST expression
$text = $self->quote($text); $text = $self->quote($text);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment