From 66c420c3d0eeb2fa0f70f8416113273c48d9887f Mon Sep 17 00:00:00 2001 From: Andrew Moore Date: Wed, 9 Jul 2008 15:52:24 -0500 Subject: [PATCH] bug 1980: updateing calls to SimpleSearch to limit number of things returned 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. Signed-off-by: Joshua Ferraro --- C4/Matcher.pm | 2 +- C4/Search.pm | 10 ++-- acqui/neworderbiblio.pl | 46 +++++++++---------- cataloguing/addbooks.pl | 16 +++---- .../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 a0f1a98207..645b2ad5ed 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 a252e1dcd4..11be63b928 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, [@servers] ); 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 +=item C + * $error is a empty unless an error is detected * \@results is an array of records. + * $total_hits is the number of hits that would have been returned with no limit =item C =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 6fb6f7c53f..d1f19323f4 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 => \@results, - 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 => \@results, + 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 91d5d6e65c..8e5327ea27 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 => \@newresults, - 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 => \@newresults, + # 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 44bc27ca30..f317bb7fa2 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 e5cff154bb..1e6133a0fb 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 @@ results found +

No results found

diff --git a/serials/subscription-bib-search.pl b/serials/subscription-bib-search.pl index f8e77ee2a2..c36a64207d 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) { -- 2.39.5