Bug 4309 Do not throw error on auth search of multiple fields
authorColin Campbell <colin.campbell@ptfs-europe.com>
Thu, 6 Jan 2011 17:49:22 +0000 (17:49 +0000)
committerChris Cormack <chrisc@catalyst.net.nz>
Mon, 24 Jan 2011 07:15:51 +0000 (20:15 +1300)
Ensures the multiple search does not throw a 500 error but
allows a single search to be used as well

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

index 9421be9..0abd506 100644 (file)
@@ -220,6 +220,7 @@ sub SearchAuthorities {
         my $dosearch;
         my $and=" \@and " ;
         my $q2;
+        my $attr_cnt = 0;
         for(my $i = 0 ; $i <= $#{$value} ; $i++)
         {
             if (@$value[$i]){
@@ -246,15 +247,16 @@ sub SearchAuthorities {
                 }
                 $attr =$attr."\"".@$value[$i]."\"";
                 $q2 .=$attr;
-            $dosearch=1;
+                $dosearch=1;
+                ++$attr_cnt;
             }#if value
         }
         ##Add how many queries generated
-        if ($query=~/\S+/){    
-          $query= $and.$query.$q2 
+        if ($query=~/\S+/){
+          $query= $and x $attr_cnt . $query . $q2;
         } else {
-          $query=$q2;    
-        }         
+          $query= $q2;
+        }
         ## Adding order
         #$query=' @or  @attr 7=2 @attr 1=Heading 0 @or  @attr 7=1 @attr 1=Heading 1'.$query if ($sortby eq "HeadingDsc");
         my $orderstring= ($sortby eq "HeadingAsc"?