C4::Search::SimpleSearch was alredy patched to let you pass in the number of
results you want back.
These instances were not using the new API. This patch makes all calls to
SimpleSearch specify a limit.
I improved the documentation of SimpleSearch a bit to include the third
returned value.
I believe there's a bug in C4::Output::pagination_bar, in that it doesn't deal
well with URLs
with only one pair of parameter=value passed to it. I'm getting around this by
passing in a second
pair that does nothing.
---
C4/Matcher.pm | 2 +-
C4/Search.pm | 10 +++--
acqui/neworderbiblio.pl | 46 ++++++++++----------
cataloguing/addbooks.pl | 16 +++----
cataloguing/value_builder/unimarc_field_4XX.pl | 5 +-
.../prog/en/modules/acqui/neworderbiblio.tmpl | 1 +
serials/subscription-bib-search.pl | 2 +-
7 files changed, 40 insertions(+), 42 deletions(-)
diff --git a/C4/Matcher.pm b/C4/Matcher.pm
index a0f1a98..645b2ad 100644
--- a/C4/Matcher.pm
+++ b/C4/Matcher.pm
@@ -661,7 +661,7 @@ sub get_matches {
# build query
my $query = join(" or ", map { "$matchpoint->{'index'}=$_" }
@source_keys);
# FIXME only searching biblio index at the moment
- my ($error, $searchresults, $total_hits) = SimpleSearch($query);
+ my ($error, $searchresults, $total_hits) = SimpleSearch($query, 0,
$max_matches);
warn "search failed ($query) $error" if $error;
foreach my $matched (@$searchresults) {
diff --git a/C4/Search.pm b/C4/Search.pm
index a252e1d..11be63b 100755
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -158,7 +158,7 @@ sub FindDuplicate {
=head2 SimpleSearch
-($error,$results) = SimpleSearch( $query, $offset, $max_results, [ @servers ]
);
+( $error, $results, $total_hits ) = SimpleSearch( $query, $offset,
$max_results, [EMAIL PROTECTED] );
This function provides a simple search API on the bibliographic catalog
@@ -172,15 +172,17 @@ 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<Output arg:>
+=item C<Output:>
+
* $error is a empty unless an error is detected
* [EMAIL PROTECTED] is an array of records.
+ * $total_hits is the number of hits that would have been returned with no
limit
=item C<usage in the script:>
=back
-my ($error, $marcresults) = SimpleSearch($query);
+my ( $error, $marcresults, $total_hits ) = SimpleSearch($query);
if (defined $error) {
$template->param(query_error => $error);
@@ -192,7 +194,7 @@ if (defined $error) {
my $hits = scalar @$marcresults;
my @results;
-for(my $i=0;$i<$hits;$i++) {
+for my $i (0..$hits) {
my %resultsloop;
my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
diff --git a/acqui/neworderbiblio.pl b/acqui/neworderbiblio.pl
index 6fb6f7c..d1f1932 100755
--- a/acqui/neworderbiblio.pl
+++ b/acqui/neworderbiblio.pl
@@ -69,14 +69,13 @@ my $input = new CGI;
#getting all CGI params into a hash.
my $params = $input->Vars;
-my $offset = $params->{'offset'} || 0;
-my $query = $params->{'q'};
-my $num = $params->{'num'};
-$num = 20 unless $num;
+my $page = $params->{'page'} || 1;
+my $query = $params->{'q'};
+my $results_per_page = $params->{'num'} || 20;
my $booksellerid = $params->{'booksellerid'};
-my $basketno = $params->{'basketno'};
-my $sub = $params->{'sub'};
+my $basketno = $params->{'basketno'};
+my $sub = $params->{'sub'};
# getting the template
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -90,7 +89,7 @@ my ( $template, $loggedinuser, $cookie ) =
get_template_and_user(
);
# Searching the catalog.
-my ($error, $marcresults) = SimpleSearch($query);
+my ($error, $marcresults, $total_hits) = SimpleSearch($query,
$results_per_page * ($page - 1), $results_per_page);
if (defined $error) {
$template->param(query_error => $error);
@@ -99,10 +98,9 @@ if (defined $error) {
exit;
}
-my $hits = scalar @$marcresults;
my @results;
-for(my $i=0;$i<$hits;$i++) {
+foreach my $i ( 0 .. scalar @$marcresults ) {
my %resultsloop;
my $marcrecord = MARC::File::USMARC::decode($marcresults->[$i]);
my $biblio = TransformMarcToKoha(C4::Context->dbh,$marcrecord,'');
@@ -115,20 +113,22 @@ for(my $i=0;$i<$hits;$i++) {
}
$template->param(
- basketno => $basketno,
- booksellerid => $booksellerid,
- resultsloop => [EMAIL PROTECTED],
- total => $hits,
- query => $query,
- virtualshelves => C4::Context->preference("virtualshelves"),
- LibraryName => C4::Context->preference("LibraryName"),
- OpacNav => C4::Context->preference("OpacNav"),
- opaccredits => C4::Context->preference("opaccredits"),
- AmazonContent => C4::Context->preference("AmazonContent"),
- opacsmallimage => C4::Context->preference("opacsmallimage"),
- opaclayoutstylesheet =>
C4::Context->preference("opaclayoutstylesheet"),
- opaccolorstylesheet =>
C4::Context->preference("opaccolorstylesheet"),
-
"BiblioDefaultView".C4::Context->preference("IntranetBiblioDefaultView") => 1,
+ basketno => $basketno,
+ booksellerid => $booksellerid,
+ resultsloop => [EMAIL PROTECTED],
+ total => $total_hits,
+ query => $query,
+ virtualshelves => C4::Context->preference("virtualshelves"),
+ LibraryName => C4::Context->preference("LibraryName"),
+ OpacNav => C4::Context->preference("OpacNav"),
+ opaccredits => C4::Context->preference("opaccredits"),
+ AmazonContent => C4::Context->preference("AmazonContent"),
+ opacsmallimage => C4::Context->preference("opacsmallimage"),
+ opaclayoutstylesheet => C4::Context->preference("opaclayoutstylesheet"),
+ opaccolorstylesheet => C4::Context->preference("opaccolorstylesheet"),
+ "BiblioDefaultView".C4::Context->preference("IntranetBiblioDefaultView")
=> 1,
+ # FIXME: pagination_bar doesn't work right with only one pair of CGI
params, so I put two in.
+ pagination_bar => pagination_bar(
"$ENV{'SCRIPT_NAME'}?bug=fix&q=$query&", getnbpages( $total_hits,
$results_per_page ), $page, 'page' ),
);
# BUILD THE TEMPLATE
diff --git a/cataloguing/addbooks.pl b/cataloguing/addbooks.pl
index 91d5d6e..8e5327e 100755
--- a/cataloguing/addbooks.pl
+++ b/cataloguing/addbooks.pl
@@ -68,7 +68,7 @@ foreach my $thisframeworkcode ( keys %$frameworks ) {
if ($query) {
# find results
- my ( $error, $marcresults, $total_hits ) = SimpleSearch($query);
+ my ( $error, $marcresults, $total_hits ) = SimpleSearch($query,
$results_per_page * ($page - 1), $results_per_page);
if ( defined $error ) {
$template->param( error => $error );
@@ -81,15 +81,11 @@ if ($query) {
my $total = scalar @$marcresults;
my @newresults = searchResults( $query, $total, $results_per_page,
$page-1, 0, @$marcresults );
$template->param(
- total => $total,
- query => $query,
- resultsloop => [EMAIL PROTECTED],
- pagination_bar => pagination_bar(
-
"/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&",
- getnbpages( $total, $results_per_page ),
- $page,
- 'page'
- ),
+ total => $total_hits,
+ query => $query,
+ resultsloop => [EMAIL PROTECTED],
+ # FIXME: pagination_bar doesn't work right with only one pair of CGI
params, so I put two in.
+ pagination_bar => pagination_bar(
"/cgi-bin/koha/cataloguing/addbooks.pl?bug=fix&q=$query&", getnbpages(
$total_hits, $results_per_page ), $page, 'page' ),
);
}
diff --git a/cataloguing/value_builder/unimarc_field_4XX.pl
b/cataloguing/value_builder/unimarc_field_4XX.pl
index 44bc27c..f317bb7 100755
--- a/cataloguing/value_builder/unimarc_field_4XX.pl
+++ b/cataloguing/value_builder/unimarc_field_4XX.pl
@@ -328,11 +328,10 @@ sub plugin {
elsif ( $op eq "do_search" ) {
my $search = $query->param('search');
my $startfrom = $query->param('startfrom');
- my $resultsperpage = $query->param('resultsperpage');
+ my $resultsperpage = $query->param('resultsperpage') || 20;
my $orderby;
- my ( $errors, $results, $total_hits ) = SimpleSearch($search);
+ my ( $errors, $results, $total_hits ) = SimpleSearch($search,
$startfrom, $resultsperpage );
my $total = scalar(@$results);
- $resultsperpage = 20 unless $resultsperpage;
# warn " biblio count : ".$total;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tmpl
b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tmpl
index e5cff15..1e6133a 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tmpl
@@ -20,6 +20,7 @@
<!-- TMPL_IF NAME="total" -->
<b><!-- TMPL_VAR NAME="total" --> results found</b>
+<!-- TMPL_VAR name='pagination_bar'-->
<!-- TMPL_ELSE -->
<h3> No results found</h3>
<p>
diff --git a/serials/subscription-bib-search.pl
b/serials/subscription-bib-search.pl
index f8e77ee..c36a642 100755
--- a/serials/subscription-bib-search.pl
+++ b/serials/subscription-bib-search.pl
@@ -78,7 +78,7 @@ if ($op eq "do_search" && $query) {
$resultsperpage= $input->param('resultsperpage');
$resultsperpage = 19 if(!defined $resultsperpage);
- my ($error, $marcrecords, $total_hits) = SimpleSearch($query);
+ my ($error, $marcrecords, $total_hits) = SimpleSearch($query, $startfrom,
$resultsperpage);
my $total = scalar @$marcrecords;
if (defined $error) {
--
1.5.6
_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches