Bug 5651: Question marks break searches w/ICU
authorJared Camins-Esakov <jcamins@bywatersolutions.com>
Tue, 5 Apr 2011 13:48:03 +0000 (15:48 +0200)
committerChris Cormack <chrisc@catalyst.net.nz>
Wed, 6 Apr 2011 03:33:58 +0000 (15:33 +1200)
When a user is doing a simple keyword search, they should not be expected to
deal with the magical behavior of question marks in Zebra. This fix escapes
question marks, and reduces the number of false positives for identifying a
"simple keyword search."

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Search.pm

index c69e787..24ed772 100644 (file)
@@ -1122,10 +1122,12 @@ sub buildQuery {
                 my $indexes_set;
 
 # If the user is sophisticated enough to specify an index, turn off field weighting, stemming, and stopword handling
-                if ( $operands[$i] =~ /(:|=)/ || $scan ) {
+                if ( $operands[$i] =~ /\w(:|=)/ || $scan ) {
                     $weight_fields    = 0;
                     $stemming         = 0;
                     $remove_stopwords = 0;
+                } else {
+                    $operands[$i] =~ s/\?/{?}/g; # need to escape question marks
                 }
                 my $operand = $operands[$i];
                 my $index   = $indexes[$i];