6786: False detection of index names in Search; make index names case insensitive
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 25 Aug 2011 11:12:38 +0000 (13:12 +0200)
committerChris Cormack <chrisc@catalyst.net.nz>
Fri, 7 Oct 2011 01:08:09 +0000 (14:08 +1300)
Fixing the regex to detect index names in ccl queries.  Changing loop
structure: looping through the index candidates in the query is faster than
testing every index name with a regex.  Making the index comparison case
insensitive will benefit users misspelling the case of an index; Zebra does not
care about it.  Test the change by searching on a word followed by a : or =
character.  Previously, when that word contained an index name like an or nb,
the search would crash.

Signed-off-by: Frédéric Demians <f.demians@tamil.fr>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
Perltidied the new block to fix indentation

Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz>
C4/Search.pm

index 343058a..b9069f5 100644 (file)
@@ -1072,15 +1072,14 @@ sub buildQuery {
 
     my $stopwords_removed;    # flag to determine if stopwords have been removed
 
-    my $cclq;
+    my $cclq       = 0;
     my $cclindexes = getIndexes();
-    if( $query !~ /\s*ccl=/ ){
-        for my $index (@$cclindexes){
-            if($query =~ /($index)(,?\w)*[:=]/){
-                $cclq = 1;
-            }
+    if ( $query !~ /\s*ccl=/ ) {
+        while ( !$cclq && $query =~ /(?:^|\W)(\w+)(,\w+)*[:=]/g ) {
+            my $dx = lc($1);
+            $cclq = grep { lc($_) eq $dx } @$cclindexes;
         }
-        $query = "ccl=$query" if($cclq);
+        $query = "ccl=$query" if $cclq;
     }
 
 # for handling ccl, cql, pqf queries in diagnostic mode, skip the rest of the steps