my $search_result =
( $result->{hits}
&& $result->{hits} > 0 ? $result->{'RECORDS'} : [] );
- return ( undef, $search_result );
+ return ( undef, $search_result, scalar($search_result) );
}
else {
# FIXME hardcoded value. See catalog/search.pl & opac-search.pl too.
my @results;
my @tmpresults;
my @zconns;
- return ( "No query entered", undef ) unless $query;
+ my $total_hits;
+ return ( "No query entered", undef, undef ) unless $query;
# Initialize & Search Zebra
for ( my $i = 0 ; $i < @servers ; $i++ ) {
. $zconns[$i]->addinfo() . " "
. $zconns[$i]->diagset();
- return ( $error, undef ) if $zconns[$i]->errcode();
+ return ( $error, undef, undef ) if $zconns[$i]->errcode();
};
if ($@) {
. $@->addinfo() . " "
. $@->diagset();
warn $error;
- return ( $error, undef );
+ return ( $error, undef, undef );
}
}
-
while ( ( my $i = ZOOM::event( \@zconns ) ) != 0 ) {
my $event = $zconns[ $i - 1 ]->last_event();
if ( $event == ZOOM::Event::ZEND ) {
my $first_record = defined( $offset ) ? $offset+1 : 1;
my $hits = $tmpresults[ $i - 1 ]->size();
+ $total_hits += $hits;
my $last_record = $hits;
if ( defined $max_results && $offset + $max_results < $hits ) {
$last_record = $offset + $max_results;
}
}
- return ( undef, \@results );
+ return ( undef, \@results, $total_hits );
}
}
# perform the search, create the results objects
# if this is a local search, use the $koha-query, if it's a federated one, use the federated-query
- my $query_to_use;
- if ( $servers[$i] =~ /biblioserver/ ) {
- $query_to_use = $koha_query;
- }
- else {
- $query_to_use = $simple_query;
- }
+ my $query_to_use = ($servers[$i] =~ /biblioserver/) ? $koha_query : $simple_query;
#$query_to_use = $simple_query if $scan;
warn $simple_query if ( $scan and $DEBUG );
my $tmpauthor;
# the minimal record in author/title (depending on MARC flavour)
- if ( C4::Context->preference("marcflavour") eq
- "UNIMARC" )
- {
- $tmptitle = MARC::Field->new(
- '200', ' ', ' ',
- a => $term,
- f => $occ
- );
+ if (C4::Context->preference("marcflavour") eq "UNIMARC") {
+ $tmptitle = MARC::Field->new('200',' ',' ', a => $term, f => $occ);
$tmprecord->append_fields($tmptitle);
- }
- else {
- $tmptitle =
- MARC::Field->new( '245', ' ', ' ', a => $term, );
- $tmpauthor =
- MARC::Field->new( '100', ' ', ' ', a => $occ, );
+ } else {
+ $tmptitle = MARC::Field->new('245',' ',' ', a => $term,);
+ $tmpauthor = MARC::Field->new('100',' ',' ', a => $occ,);
$tmprecord->append_fields($tmptitle);
$tmprecord->append_fields($tmpauthor);
}
- $results_hash->{'RECORDS'}[$j] =
- $tmprecord->as_usmarc();
+ $results_hash->{'RECORDS'}[$j] = $tmprecord->as_usmarc();
}
# not an index scan
if ( $index eq 'yr' ) {
$index .= ",st-numeric";
$indexes_set++;
- (
- $stemming, $auto_truncation,
- $weight_fields, $fuzzy_enabled,
- $remove_stopwords
- ) = ( 0, 0, 0, 0, 0 );
+ $stemming = $auto_truncation = $weight_fields = $fuzzy_enabled = $remove_stopwords = 0;
}
# Date of Acquisition
elsif ( $index eq 'acqdate' ) {
$index .= ",st-date-normalized";
$indexes_set++;
- (
+ $stemming = $auto_truncation = $weight_fields = $fuzzy_enabled = $remove_stopwords = 0;
+ }
+ # 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,
$remove_stopwords
) = ( 0, 0, 0, 0, 0 );
- }
+ }
# Set default structure attribute (word list)
my $struct_attr;
- unless ( !$index || $index =~ /(st-|phr|ext|wrdl)/ ) {
+ unless ( $indexes_set || !$index || $index =~ /(st-|phr|ext|wrdl)/ ) {
$struct_attr = ",wrdl";
}
);
$bsth->execute();
while ( my $bdata = $bsth->fetchrow_hashref ) {
- $itemtypes{ $bdata->{'itemtype'} }->{description} =
- $bdata->{'description'};
- $itemtypes{ $bdata->{'itemtype'} }->{imageurl} = $bdata->{'imageurl'};
- $itemtypes{ $bdata->{'itemtype'} }->{summary} = $bdata->{'summary'};
- $itemtypes{ $bdata->{'itemtype'} }->{notforloan} =
- $bdata->{'notforloan'};
+ foreach (qw(description imageurl summary notforloan)) {
+ $itemtypes{ $bdata->{'itemtype'} }->{$_} = $bdata->{$_};
+ }
}
#search item field code
$times = $offset + $results_per_page;
}
else {
- $times = $hits;
+ $times = $hits; # FIXME: if $hits is undefined, why do we want to equal it?
}
# loop through all of the records we've retrieved
for ( my $i = $offset ; $i <= $times - 1 ; $i++ ) {
- my $marcrecord;
- $marcrecord = MARC::File::USMARC::decode( $marcresults[$i] );
+ my $marcrecord = MARC::File::USMARC::decode( $marcresults[$i] );
my $oldbiblio = TransformMarcToKoha( $dbh, $marcrecord, '' );
$oldbiblio->{result_number} = $i + 1;
if ( $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} =~ /^http:/ ) {
$oldbiblio->{imageurl} =
$itemtypes{ $oldbiblio->{itemtype} }->{imageurl};
- $oldbiblio->{description} =
- $itemtypes{ $oldbiblio->{itemtype} }->{description};
- }
- else {
+ } else {
$oldbiblio->{imageurl} =
getitemtypeimagesrc() . "/"
. $itemtypes{ $oldbiblio->{itemtype} }->{imageurl}
if ( $itemtypes{ $oldbiblio->{itemtype} }->{imageurl} );
- $oldbiblio->{description} =
- $itemtypes{ $oldbiblio->{itemtype} }->{description};
}
- my $aisbn=$oldbiblio->{'isbn'};
+ my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $oldbiblio->{biblionumber} ) );
+ $oldbiblio->{authorised_value_images} = $biblio_authorised_value_images;
+ my $aisbn = $oldbiblio->{'isbn'};
$aisbn =~ /(\d*[X]*)/;
- $oldbiblio->{'amazonisbn'} = $1;
+ $oldbiblio->{amazonisbn} = $1;
+ $oldbiblio->{description} = $itemtypes{ $oldbiblio->{itemtype} }->{description};
# Build summary if there is one (the summary is defined in the itemtypes table)
# FIXME: is this used anywhere, I think it can be commented out? -- JF
if ( $itemtypes{ $oldbiblio->{itemtype} }->{summary} ) {
$oldbiblio->{summary} = $summary;
}
-# Add search-term highlighting to the whole record where they match using <span>s
+ # save an author with no <span> tag, for the <a href=search.pl?q=<!--tmpl_var name="author"-->> link
+ $oldbiblio->{'author_nospan'} = $oldbiblio->{'author'};
+ $oldbiblio->{'title_nospan'} = $oldbiblio->{'title'};
+ # Add search-term highlighting to the whole record where they match using <span>s
if (C4::Context->preference("OpacHighlightedWords")){
my $searchhighlightblob;
for my $highlight_field ( $marcrecord->fields ) {
$searchhighlightblob = ' ... '.$searchhighlightblob if $searchhighlightblob;
$oldbiblio->{'searchhighlightblob'} = $searchhighlightblob;
}
-# save an author with no <span> tag, for the <a href=search.pl?q=<!--tmpl_var name="author"-->> link
- $oldbiblio->{'author_nospan'} = $oldbiblio->{'author'};
# Add search-term highlighting to the title, subtitle, etc. fields
for my $term ( keys %$span_terms_hashref ) {
my $old_term = $term;
if ( length($term) > 3 ) {
$term =~ s/(.*=|\)|\(|\+|\.|\?|\[|\]|\\|\*)//g;
- $oldbiblio->{'title'} =~
- s/$term/<span class=\"term\">$&<\/span>/gi;
- $oldbiblio->{'subtitle'} =~
- s/$term/<span class=\"term\">$&<\/span>/gi;
- $oldbiblio->{'author'} =~
- s/$term/<span class=\"term\">$&<\/span>/gi;
- $oldbiblio->{'publishercode'} =~
- s/$term/<span class=\"term\">$&<\/span>/gi;
- $oldbiblio->{'place'} =~
- s/$term/<span class=\"term\">$&<\/span>/gi;
- $oldbiblio->{'pages'} =~
- s/$term/<span class=\"term\">$&<\/span>/gi;
- $oldbiblio->{'notes'} =~
- s/$term/<span class=\"term\">$&<\/span>/gi;
- $oldbiblio->{'size'} =~
- s/$term/<span class=\"term\">$&<\/span>/gi;
+ foreach(qw(title subtitle author publishercode place pages notes size)) {
+ $oldbiblio->{$_} =~ s/$term/<span class=\"term\">$&<\/span>/gi;
+ }
}
}
# XSLT processing of some stuff
if (C4::Context->preference("XSLTResultsDisplay") ) {
- my $newxmlrecord = XSLTParse4Display($oldbiblio->{biblionumber},'Results');
+ my $newxmlrecord = XSLTParse4Display($oldbiblio->{biblionumber},C4::Context->config('opachtdocs')."/prog/en/xslt/MARC21slim2OPACResults.xsl");
$oldbiblio->{XSLTResultsRecord} = $newxmlrecord;
}
$oldbiblio->{orderedcount} = $ordered_count;
$oldbiblio->{isbn} =~
s/-//g; # deleting - in isbn to enable amazon content
+ $oldbiblio->{'authorised_value_images'} = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $oldbiblio->{'biblionumber'} ) );
push( @newresults, $oldbiblio );
}
return @newresults;