[Koha-patches] [PATCH] Enabling SimpleSearch to return the total number of hits to caller
Chris Nighswonger
cnighswonger at foundations.edu
Tue Apr 15 11:03:31 CEST 2008
---
C4/Search.pm | 13 +++++++------
labels/label-item-search.pl | 5 +++--
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/C4/Search.pm b/C4/Search.pm
index a3ffc09..2c572b7 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -221,7 +221,7 @@ sub SimpleSearch {
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.
@@ -229,7 +229,7 @@ sub SimpleSearch {
my @results;
my @tmpresults;
my @zconns;
- return ( "No query entered", undef ) unless $query;
+ return ( "No query entered", undef, undef ) unless $query;
# Initialize & Search Zebra
for ( my $i = 0 ; $i < @servers ; $i++ ) {
@@ -246,7 +246,7 @@ sub SimpleSearch {
. $zconns[$i]->addinfo() . " "
. $zconns[$i]->diagset();
- return ( $error, undef ) if $zconns[$i]->errcode();
+ return ( $error, undef, undef ) if $zconns[$i]->errcode();
};
if ($@) {
@@ -257,16 +257,17 @@ sub SimpleSearch {
. $@->addinfo() . " "
. $@->diagset();
warn $error;
- return ( $error, undef );
+ return ( $error, undef, undef );
}
}
-
+ my $total_hits;
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;
@@ -279,7 +280,7 @@ sub SimpleSearch {
}
}
- return ( undef, \@results );
+ return ( undef, \@results, $total_hits );
}
}
diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl
index 4bd4a5a..22ea645 100755
--- a/labels/label-item-search.pl
+++ b/labels/label-item-search.pl
@@ -74,7 +74,8 @@ if ( $op eq "do_search" ) {
#catalogsearch( $dbh, \@tags, \@and_or, \@excluding, \@operator, \@value,
# $startfrom * $resultsperpage,
# $resultsperpage, $orderby );
- ( $error, $marcresults ) = SimpleSearch( $marclist[0], $startfrom, $resultsperpage );
+ ( $error, $marcresults, $total ) = SimpleSearch( $marclist[0], $startfrom, $resultsperpage );
+ warn "\$total=$total";
if ($marcresults) {
$show_results = scalar @$marcresults;
} else {
@@ -182,7 +183,7 @@ if ( $show_results ) {
startfromnext => $startfrom + min( $resultsperpage, scalar @results ),
startfromprev => max( $startfrom - $resultsperpage, 0 ),
searchdata => \@field_data,
- total => (scalar @results),
+ total => $total,
from => $startfrom + 1,
to => $startfrom + min( $resultsperpage, scalar @results ),
numbers => \@numbers,
--
1.5.3.7
More information about the Koha-patches
mailing list