X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FSearch.pm;h=ab7cb5972188feb5dabb20bd302e08ae1dede1ca;hb=ce849240ad67131ead68f4339f49e861c6719882;hp=a8d5ba7b4478854826c3ef073a23de5c57ceb0da;hpb=b00c36989f2c480263478d358e4fcf670d047331;p=koha.git diff --git a/C4/Search.pm b/C4/Search.pm index a8d5ba7b44..ab7cb59721 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -30,6 +30,8 @@ use C4::XSLT; use C4::Branch; use C4::Reserves; # CheckReserves use C4::Debug; +use C4::Items; +use YAML; use URI::Escape; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); @@ -121,18 +123,19 @@ sub FindDuplicate { } } - # FIXME: add error handling - my ( $error, $searchresults ) = SimpleSearch($query); # FIXME :: hardcoded ! + my ( $error, $searchresults, undef ) = SimpleSearch($query); # FIXME :: hardcoded ! my @results; - foreach my $possible_duplicate_record (@$searchresults) { - my $marcrecord = - MARC::Record->new_from_usmarc($possible_duplicate_record); - my $result = TransformMarcToKoha( $dbh, $marcrecord, '' ); - - # FIXME :: why 2 $biblionumber ? - if ($result) { - push @results, $result->{'biblionumber'}; - push @results, $result->{'title'}; + if (!defined $error) { + foreach my $possible_duplicate_record (@{$searchresults}) { + my $marcrecord = + MARC::Record->new_from_usmarc($possible_duplicate_record); + my $result = TransformMarcToKoha( $dbh, $marcrecord, '' ); + + # FIXME :: why 2 $biblionumber ? + if ($result) { + push @results, $result->{'biblionumber'}; + push @results, $result->{'title'}; + } } } return @results; @@ -154,12 +157,16 @@ This function provides a simple search API on the bibliographic catalog * $max_results - if present, determines the maximum number of records to fetch. undef is All. defaults to undef. -=item C +=item C - * $error is a empty unless an error is detected - * \@results is an array of records. + Returns an array consisting of three elements + * $error is undefined unless an error is detected + * $results is a reference to an array of records. * $total_hits is the number of hits that would have been returned with no limit + If an error is returned the two other return elements are undefined. If error itself is undefined + the other two elements are always defined + =item C =back @@ -173,23 +180,23 @@ if (defined $error) { exit; } -my $hits = scalar @$marcresults; +my $hits = @{$marcresults}; my @results; -for my $i (0..$hits) { - my %resultsloop; - my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]); - my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,''); - - #build the hash for the template. - $resultsloop{title} = $biblio->{'title'}; - $resultsloop{subtitle} = $biblio->{'subtitle'}; - $resultsloop{biblionumber} = $biblio->{'biblionumber'}; - $resultsloop{author} = $biblio->{'author'}; - $resultsloop{publishercode} = $biblio->{'publishercode'}; - $resultsloop{publicationyear} = $biblio->{'publicationyear'}; +for my $r ( @{$marcresults} ) { + my $marcrecord = MARC::File::USMARC::decode($r); + my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,q{}); + + #build the iarray of hashs for the template. + push @results, { + title => $biblio->{'title'}, + subtitle => $biblio->{'subtitle'}, + biblionumber => $biblio->{'biblionumber'}, + author => $biblio->{'author'}, + publishercode => $biblio->{'publishercode'}, + publicationyear => $biblio->{'publicationyear'}, + }; - push @results, \%resultsloop; } $template->param(result=>\@results); @@ -207,14 +214,14 @@ sub SimpleSearch { return ( undef, $search_result, scalar($result->{hits}) ); } else { + return ( 'No query entered', undef, undef ) unless $query; # FIXME hardcoded value. See catalog/search.pl & opac-search.pl too. - my @servers = defined ( $servers ) ? @$servers : ( "biblioserver" ); - my @results; + my @servers = defined ( $servers ) ? @$servers : ( 'biblioserver' ); my @zoom_queries; my @tmpresults; my @zconns; - my $total_hits; - return ( "No query entered", undef, undef ) unless $query; + my $results = []; + my $total_hits = 0; # Initialize & Search Zebra for ( my $i = 0 ; $i < @servers ; $i++ ) { @@ -258,7 +265,7 @@ sub SimpleSearch { for my $j ( $first_record..$last_record ) { my $record = $tmpresults[ $i - 1 ]->record( $j-1 )->raw(); # 0 indexed - push @results, $record; + push @{$results}, $record; } } } @@ -270,7 +277,7 @@ sub SimpleSearch { $zoom_query->destroy(); } - return ( undef, \@results, $total_hits ); + return ( undef, $results, $total_hits ); } } @@ -352,10 +359,10 @@ sub getRecords { # Note: sort will override rank my $sort_by; foreach my $sort (@sort_by) { - if ( $sort eq "author_az" ) { + if ( $sort eq "author_az" || $sort eq "author_asc" ) { $sort_by .= "1=1003 {$code} = $field->subfield( $subfieldstosearch{$code} ); } - my $hbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch' : 'holdingbranch'; - my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch'; + # Hidden items + my @items = ($item); + my (@hiddenitems) = GetHiddenItemnumbers(@items); + $item->{'hideatopac'} = 1 if (@hiddenitems); + + my $hbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'homebranch' : 'holdingbranch'; + my $otherbranch = C4::Context->preference('HomeOrHoldingBranch') eq 'homebranch' ? 'holdingbranch' : 'homebranch'; + # set item's branch name, use HomeOrHoldingBranch syspref first, fall back to the other one if ($item->{$hbranch}) { $item->{'branchname'} = $branches{$item->{$hbranch}}; @@ -1659,6 +1676,7 @@ sub searchResults { || $item->{itemlost} || $item->{damaged} || $item->{notforloan} > 0 + || $item->{hideatopac} || $reservestatus eq 'Waiting' || ($transfertwhen ne '')) { @@ -1670,11 +1688,11 @@ sub searchResults { $item->{status} = $item->{wthdrawn} . "-" . $item->{itemlost} . "-" . $item->{damaged} . "-" . $item->{notforloan}; $other_count++; - my $key = $prefix . $item->{status}; - foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber)) { - $other_items->{$key}->{$_} = $item->{$_}; - } - $other_items->{$key}->{intransit} = ($transfertwhen ne '') ? 1 : 0; + my $key = $prefix . $item->{status}; + foreach (qw(wthdrawn itemlost damaged branchname itemcallnumber hideatopac)) { + $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}; @@ -1686,7 +1704,7 @@ sub searchResults { $can_place_holds = 1; $available_count++; $available_items->{$prefix}->{count}++ if $item->{$hbranch}; - foreach (qw(branchname itemcallnumber)) { + foreach (qw(branchname itemcallnumber hideatopac)) { $available_items->{$prefix}->{$_} = $item->{$_}; } $available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} }; @@ -2268,7 +2286,7 @@ sub NZorder { # sort the hash and return the same structure as GetRecords (Zebra querying) my $result_hash; my $numbers = 0; - if ( $ordering eq 'author_za' ) { # sort by author desc + if ( $ordering eq 'author_za' || $ordering eq 'author_dsc' ) { # sort by author desc foreach my $key ( sort { $b cmp $a } ( keys %result ) ) { $result_hash->{'RECORDS'}[ $numbers++ ] = $result{$key}->as_usmarc(); @@ -2641,11 +2659,11 @@ AND (authtypecode IS NOT NULL AND authtypecode<>\"\")|); warn "BIBLIOADDSAUTHORITIES: $error"; return (0,0) ; } - if ($results && scalar(@$results)==1) { + if ( @{$results} == 1 ) { my $marcrecord = MARC::File::USMARC::decode($results->[0]); $field->add_subfields('9'=>$marcrecord->field('001')->data); $countlinked++; - } elsif (scalar(@$results)>1) { + } elsif ( @{$results} > 1 ) { #More than One result #This can comes out of a lack of a subfield. # my $marcrecord = MARC::File::USMARC::decode($results->[0]);