Merge branch 'serials_mods' of git://github.com/colinsc/koha into to-push
[koha.git] / C4 / Search.pm
index 47ac7a3..554174c 100644 (file)
@@ -27,6 +27,7 @@ use XML::Simple;
 use C4::Dates qw(format_date);
 use C4::XSLT;
 use C4::Branch;
+use C4::Reserves;    # CheckReserves
 use C4::Debug;
 use YAML;
 use URI::Escape;
@@ -814,7 +815,7 @@ sub getIndexes{
                     'biblionumber',
                     'bio',
                     'biography',
-                    'callnum',          
+                    'callnum',
                     'cfn',
                     'Chronological-subdivision',
                     'cn-bib-source',
@@ -927,7 +928,7 @@ sub getIndexes{
                     'Title-uniform-seealso',
                     'totalissues',
                     'yr',
-                    
+
                     # items indexes
                     'acqsource',
                     'barcode',
@@ -944,6 +945,7 @@ sub getIndexes{
                     'holdingbranch',
                     'homebranch',
                     'issues',
+                    'item',
                     'itemnumber',
                     'itype',
                     'Local-classification',
@@ -964,10 +966,10 @@ sub getIndexes{
                     'stack',
                     'uri',
                     'withdrawn',
-                    
+
                     # subject related
                   );
-                  
+
     return \@indexes;
 }
 
@@ -1114,11 +1116,11 @@ sub buildQuery {
                     ) = ( 0, 0, 0, 0, 0 );
 
                 }
-                
+
                 if(not $index){
                     $index = 'kw';
                 }
-                
+
                 # Set default structure attribute (word list)
                 my $struct_attr;
                 unless ( $indexes_set || !$index || $index =~ /(st-|phr|ext|wrdl)/ ) {
@@ -1141,7 +1143,7 @@ sub buildQuery {
                 if ($auto_truncation){
                                        unless ( $index =~ /(st-|phr|ext)/ ) {
                                                #FIXME only valid with LTR scripts
-                                               $operand=join(" ",map{ 
+                                               $operand=join(" ",map{
                                                                                        (index($_,"*")>0?"$_":"$_*")
                                                                                         }split (/\s+/,$operand));
                                                warn $operand if $DEBUG;
@@ -1305,7 +1307,9 @@ sub buildQuery {
     # Normalize the query and limit strings
     # This is flawed , means we can't search anything with : in it
     # if user wants to do ccl or cql, start the query with that
-    $query =~ s/:/=/g;
+#    $query =~ s/:/=/g;
+    $query =~ s/(?<=(ti|au|pb|su|an|kw|mc)):/=/g;
+    $query =~ s/(?<=rtrn):/=/g;
     $limit =~ s/:/=/g;
     for ( $query, $query_desc, $limit, $limit_desc ) {
         s/  / /g;    # remove extra spaces
@@ -1513,6 +1517,7 @@ sub searchResults {
         my $itemdamaged_count     = 0;
         my $item_in_transit_count = 0;
         my $can_place_holds       = 0;
+       my $item_onhold_count     = 0;
         my $items_count           = scalar(@fields);
         my $maxitems =
           ( C4::Context->preference('maxItemsinSearchResults') )
@@ -1570,6 +1575,10 @@ sub searchResults {
                 my $transfertwhen = '';
                 my ($transfertfrom, $transfertto);
 
+                # is item on the reserve shelf?
+               my $reservestatus = 0;
+               my $reserveitem;
+
                 unless ($item->{wthdrawn}
                         || $item->{itemlost}
                         || $item->{damaged}
@@ -1589,6 +1598,7 @@ sub searchResults {
                     #        should map transit status to record indexed in Zebra.
                     #
                     ($transfertwhen, $transfertfrom, $transfertto) = C4::Circulation::GetTransfers($item->{itemnumber});
+                   ($reservestatus, $reserveitem) = C4::Reserves::CheckReserves($item->{itemnumber});
                 }
 
                 # item is withdrawn, lost or damaged
@@ -1596,12 +1606,14 @@ sub searchResults {
                     || $item->{itemlost}
                     || $item->{damaged}
                     || $item->{notforloan}
+                   || $reservestatus eq 'Waiting'
                     || ($transfertwhen ne ''))
                 {
                     $wthdrawn_count++        if $item->{wthdrawn};
                     $itemlost_count++        if $item->{itemlost};
                     $itemdamaged_count++     if $item->{damaged};
                     $item_in_transit_count++ if $transfertwhen ne '';
+                   $item_onhold_count++     if $reservestatus eq 'Waiting';
                     $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan};
                     $other_count++;
 
@@ -1610,6 +1622,7 @@ sub searchResults {
                        $other_items->{$key}->{$_} = $item->{$_};
                                        }
                     $other_items->{$key}->{intransit} = ($transfertwhen ne '') ? 1 : 0;
+                    $other_items->{$key}->{onhold} = ($reservestatus) ? 1 : 0;
                                        $other_items->{$key}->{notforloan} = GetAuthorisedValueDesc('','',$item->{notforloan},'','',$notforloan_authorised_value) if $notforloan_authorised_value;
                                        $other_items->{$key}->{count}++ if $item->{$hbranch};
                                        $other_items->{$key}->{location} = $shelflocations->{ $item->{location} };
@@ -1647,6 +1660,9 @@ sub searchResults {
         }
 
         # XSLT processing of some stuff
+       use C4::Charset;
+       SetUTF8Flag($marcrecord);
+       $debug && warn $marcrecord->as_formatted;
         if (C4::Context->preference("XSLTResultsDisplay") && !$scan) {
             $oldbiblio->{XSLTResultsRecord} = XSLTParse4Display(
                 $oldbiblio->{biblionumber}, $marcrecord, 'Results' );
@@ -1671,6 +1687,7 @@ sub searchResults {
         $oldbiblio->{itemlostcount}        = $itemlost_count;
         $oldbiblio->{damagedcount}         = $itemdamaged_count;
         $oldbiblio->{intransitcount}       = $item_in_transit_count;
+        $oldbiblio->{onholdcount}          = $item_onhold_count;
         $oldbiblio->{orderedcount}         = $ordered_count;
         $oldbiblio->{isbn} =~
           s/-//g;    # deleting - in isbn to enable amazon content
@@ -2503,6 +2520,7 @@ OR adds a new authority record
 
 =item C<BUGS>
     * I had to add this to Search.pm (instead of the logical Biblio.pm) because of a circular dependency (this sub uses SimpleSearch, and Search.pm uses Biblio.pm)
+
 =back
 
 =cut