Browse Source

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 <jmf@liblime.com>
3.0.x
Andrew Moore 16 years ago
committed by Joshua Ferraro
parent
commit
66c420c3d0
  1. 2
      C4/Matcher.pm
  2. 10
      C4/Search.pm
  3. 46
      acqui/neworderbiblio.pl
  4. 16
      cataloguing/addbooks.pl
  5. 5
      cataloguing/value_builder/unimarc_field_4XX.pl
  6. 1
      koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderbiblio.tmpl
  7. 2
      serials/subscription-bib-search.pl

2
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) {

10
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<Output arg:>
=item C<Output:>
* $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<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,'');

46
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

16
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' ),
);
}

5
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;

1
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>

2
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) {

Loading…
Cancel
Save