use C4::Search::PazPar2;
use XML::Simple;
use C4::Dates qw(format_date);
+use C4::Members qw(GetHideLostItemsPreference);
use C4::XSLT;
use C4::Branch;
use C4::Reserves; # CheckReserves
}
}
- # 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;
* $max_results - if present, determines the maximum number of records to fetch. undef is All. defaults to undef.
-=item C<Output:>
+=item C<Return:>
- * $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<usage in the script:>
=back
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);
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++ ) {
for my $j ( $first_record..$last_record ) {
my $record = $tmpresults[ $i - 1 ]->record( $j-1 )->raw(); # 0 indexed
- push @results, $record;
+ push @{$results}, $record;
}
}
}
$zoom_query->destroy();
}
- return ( undef, \@results, $total_hits );
+ return ( undef, $results, $total_hits );
}
}
$sort_by .= "1=9003 >i ";
}
elsif ( $sort eq "call_number_asc" ) {
- $sort_by .= "1=20 <i ";
+ $sort_by .= "1=8007 <i ";
}
elsif ( $sort eq "call_number_dsc" ) {
- $sort_by .= "1=20 >i ";
+ $sort_by .= "1=8007 >i ";
}
elsif ( $sort eq "pubdate_asc" ) {
$sort_by .= "1=31 <i ";
warn "Ignoring unrecognized sort '$sort' requested" if $sort_by;
}
}
- if ($sort_by) {
+ if ($sort_by && !$scan) {
if ( $results[$i]->sort( "yaz", $sort_by ) < 0 ) {
warn "WARNING sort $sort_by failed";
}
# fix the length that will display in the label,
my $facet_label_value = $one_facet;
+ my $facet_max_length =
+ C4::Context->preference('FacetLabelTruncationLength') || 20;
$facet_label_value =
- substr( $one_facet, 0, 20 ) . "..."
- unless length($facet_label_value) <= 20;
+ substr( $one_facet, 0, $facet_max_length ) . "..."
+ if length($facet_label_value) > $facet_max_length;
# if it's a branch, label by the name, not the code,
if ( $link_value =~ /branch/ ) {
'Title',
'Title-cover',
'Title-series',
+ 'Title-host',
'Title-uniform',
'Title-uniform-heading',
'Title-uniform-see',
'reserves',
'restricted',
'stack',
+ 'stocknumber',
+ 'inv',
'uri',
'withdrawn',
my $indexes_set;
# If the user is sophisticated enough to specify an index, turn off field weighting, stemming, and stopword handling
- if ( $operands[$i] =~ /(:|=)/ || $scan ) {
+ if ( $operands[$i] =~ /\w(:|=)/ || $scan ) {
$weight_fields = 0;
$stemming = 0;
$remove_stopwords = 0;
+ } else {
+ $operands[$i] =~ s/\?/{?}/g; # need to escape question marks
}
my $operand = $operands[$i];
my $index = $indexes[$i];
}
# ISBN,ISSN,Standard Number, don't need special treatment
elsif ( $index eq 'nb' || $index eq 'ns' ) {
- $indexes_set++;
(
$stemming, $auto_truncation,
$weight_fields, $fuzzy_enabled,
# Set default structure attribute (word list)
my $struct_attr = q{};
- unless ( $indexes_set || !$index || $index =~ /(st-|phr|ext|wrdl)/ ) {
+ unless ( $indexes_set || !$index || $index =~ /(st-|phr|ext|wrdl|nb|ns)/ ) {
$struct_attr = ",wrdl";
}
# 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/(?<=(ti|au|pb|su|an|kw|mc)):/=/g;
+ $query =~ s/(?<=(ti|au|pb|su|an|kw|mc|nb|ns)):/=/g;
$query =~ s/(?<=(wrdl)):/=/g;
$query =~ s/(?<=(trn|phr)):/=/g;
$limit =~ s/:/=/g;
$oldbiblio->{result_number} = $i + 1;
# add imageurl to itemtype if there is one
- $oldbiblio->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} );
+ $oldbiblio->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} );
- $oldbiblio->{'authorised_value_images'} = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $oldbiblio->{'biblionumber'}, $marcrecord ) );
+ $oldbiblio->{'authorised_value_images'} = ($search_context eq 'opac' && C4::Context->preference('AuthorisedValueImages')) || ($search_context eq 'intranet' && C4::Context->preference('StaffAuthorisedValueImages')) ? C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $oldbiblio->{'biblionumber'}, $marcrecord ) ) : [];
$oldbiblio->{normalized_upc} = GetNormalizedUPC( $marcrecord,$marcflavour);
$oldbiblio->{normalized_ean} = GetNormalizedEAN( $marcrecord,$marcflavour);
$oldbiblio->{normalized_oclc} = GetNormalizedOCLCNumber($marcrecord,$marcflavour);
my $prefix = $item->{$hbranch} . '--' . $item->{location} . $item->{itype} . $item->{itemcallnumber};
# For each grouping of items (onloan, available, unavailable), we build a key to store relevant info about that item
- if ( $item->{onloan} ) {
+ my $userenv = C4::Context->userenv;
+ if ( $item->{onloan} && !(C4::Members::GetHideLostItemsPreference($userenv->{'number'}) && $item->{itemlost}) ) {
$onloan_count++;
my $key = $prefix . $item->{onloan} . $item->{barcode};
$onloan_items->{$key}->{due_date} = format_date($item->{onloan});
$onloan_items->{$key}->{branchname} = $item->{branchname};
$onloan_items->{$key}->{location} = $shelflocations->{ $item->{location} };
$onloan_items->{$key}->{itemcallnumber} = $item->{itemcallnumber};
- $onloan_items->{$key}->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $item->{itype} }->{imageurl} );
+ $onloan_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
# if something's checked out and lost, mark it as 'long overdue'
if ( $item->{itemlost} ) {
$onloan_items->{$prefix}->{longoverdue}++;
$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} };
- $other_items->{$key}->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $item->{itype} }->{imageurl} );
+ $other_items->{$key}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
}
# item is available
else {
$available_items->{$prefix}->{$_} = $item->{$_};
}
$available_items->{$prefix}->{location} = $shelflocations->{ $item->{location} };
- $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes{ $item->{itype} }->{imageurl} );
+ $available_items->{$prefix}->{imageurl} = getitemtypeimagelocation( $search_context, $itemtypes{ $item->{itype} }->{imageurl} );
}
}
} # notforloan, item level and biblioitem level
$oldbiblio->{orderedcount} = $ordered_count;
$oldbiblio->{isbn} =~
s/-//g; # deleting - in isbn to enable amazon content
+
+ if (C4::Context->preference("AlternateHoldingsField") && $items_count == 0) {
+ my $fieldspec = C4::Context->preference("AlternateHoldingsField");
+ my $subfields = substr $fieldspec, 3;
+ my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
+ my @alternateholdingsinfo = ();
+ my @holdingsfields = $marcrecord->field(substr $fieldspec, 0, 3);
+ my $alternateholdingscount = 0;
+
+ for my $field (@holdingsfields) {
+ my %holding = ( holding => '' );
+ my $havesubfield = 0;
+ for my $subfield ($field->subfields()) {
+ if ((index $subfields, $$subfield[0]) >= 0) {
+ $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
+ $holding{'holding'} .= $$subfield[1];
+ $havesubfield++;
+ }
+ }
+ if ($havesubfield) {
+ push(@alternateholdingsinfo, \%holding);
+ $alternateholdingscount++;
+ }
+ }
+
+ $oldbiblio->{'ALTERNATEHOLDINGS'} = \@alternateholdingsinfo;
+ $oldbiblio->{'alternateholdings_count'} = $alternateholdingscount;
+ }
+
push( @newresults, $oldbiblio )
if(not $hidelostitems
or (($items_count > $itemlost_count )
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]);