Bug 28290: Don't send subfields to 'as_string' if none to send
[koha-ffzg.git] / C4 / Search.pm
index 0ee8b5b..14935ab 100644 (file)
@@ -390,6 +390,12 @@ sub getRecords {
             elsif ( $sort eq "title_za" || $sort eq "title_dsc" ) {
                 $sort_by .= "1=4 >i ";
             }
+            elsif ( $sort eq "biblionumber_az" || $sort eq "biblionumber_asc" ) {
+                $sort_by .= "1=12 <i ";
+            }
+            elsif ( $sort eq "biblionumber_za" || $sort eq "biblionumber_dsc" ) {
+                $sort_by .= "1=12 >i ";
+            }
             else {
                 warn "Ignoring unrecognized sort '$sort' requested" if $sort_by;
             }
@@ -1416,7 +1422,14 @@ sub buildQuery {
                     if ( $index eq 'nb' ) {
                         if ( C4::Context->preference("SearchWithISBNVariations") ) {
                             my @isbns = C4::Koha::GetVariationsOfISBN( $operand );
-                            $operands[$i] = $operand =  '(nb=' . join(' OR nb=', @isbns) . ')';
+                            $operands[$i] = $operand = '(' . join( ' OR ', map { 'nb=' . $_ } @isbns ) . ')';
+                            $indexes[$i] = $index = 'kw';
+                        }
+                    }
+                    if ( $index eq 'ns' ) {
+                        if ( C4::Context->preference("SearchWithISSNVariations") ) {
+                            my @issns = C4::Koha::GetVariationsOfISSN( $operand );
+                            $operands[$i] = $operand = '(' . join( ' OR ', map { 'ns=' . $_ } @issns ) . ')';
                             $indexes[$i] = $index = 'kw';
                         }
                     }
@@ -1800,6 +1813,12 @@ sub searchResults {
             foreach my $code ( keys %subfieldstosearch ) {
                 $item->{$code} = $field->subfield( $subfieldstosearch{$code} );
             }
+
+            unless ( $item->{itemnumber} ) {
+                warn "MARC item without itemnumber retrieved for biblio ($oldbiblio->{biblionumber})";
+                next;
+            }
+
             $item->{description} = $itemtypes{ $item->{itype} }{translated_description} if $item->{itype};
 
             # OPAC hidden items
@@ -1895,8 +1914,16 @@ sub searchResults {
                     # FIXME: to avoid having the query the database like this, and to make
                     #        the in transit status count as unavailable for search limiting,
                     #        should map transit status to record indexed in Zebra.
-                    #
-                    ($transfertwhen, $transfertfrom, $transfertto) = C4::Circulation::GetTransfers($item->{itemnumber});
+
+                    my $item_object = Koha::Items->find($item->{itemnumber});
+                    my $transfer = defined($item_object) ? $item_object->get_transfer : undef;
+                    ( $transfertwhen, $transfertfrom, $transfertto ) =
+                      defined($transfer)
+                      ? (
+                        $transfer->datesent, $transfer->frombranch,
+                        $transfer->tobranch
+                      )
+                      : ( '', '', '' );
                     $reservestatus = C4::Reserves::GetReserveStatus( $item->{itemnumber} );
                     if ( C4::Context->preference('UseRecalls') ) {
                         if ( Koha::Recalls->search({ item_id => $item->{itemnumber}, status => 'waiting' })->count ) {