use List::Util qw(max);
use Storable qw(dclone);
+use Text::ParseWords qw(shellwords);
#####################################################################
# Constants
# 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
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 ':') {
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 {
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;