FRBR: fixed paging through grouped results
authorGalen Charlton <galen.charlton@liblime.com>
Mon, 11 Feb 2008 22:21:49 +0000 (16:21 -0600)
committerJoshua Ferraro <jmf@liblime.com>
Mon, 11 Feb 2008 22:35:17 +0000 (16:35 -0600)
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Search.pm
opac/opac-search.pl

index a7d8ecf..2235d62 100644 (file)
@@ -21,6 +21,8 @@ use C4::Context;
 use C4::Biblio;    # GetMarcFromKohaField
 use C4::Koha;      # getFacets
 use Lingua::Stem;
+use C4::Search::PazPar2;
+use XML::Simple;
 use C4::Dates qw(format_date);
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG);
@@ -611,9 +613,6 @@ sub getRecords {
     return ( undef, $results_hashref, \@facets_loop );
 }
 
-use C4::Search::PazPar2;
-use XML::Simple;
-use Data::Dumper;
 sub pazGetRecords {
     my (
         $koha_query,       $simple_query, $sort_by_ref,    $servers_ref,
@@ -629,9 +628,14 @@ sub pazGetRecords {
     # do results
     my $results_hashref = {};
     my $stats = XMLin($paz->stat);
-    $results_hashref->{'biblioserver'}->{'hits'} = $stats->{'hits'};
     my $results = XMLin($paz->show($offset, $results_per_page, 'work-title:1'), forcearray => 1);
-    
+   
+    # for a grouped search result, the number of hits
+    # is the number of groups returned; 'bib_hits' will have
+    # the total number of bibs. 
+    $results_hashref->{'biblioserver'}->{'hits'} = $results->{'merged'}->[0];
+    $results_hashref->{'biblioserver'}->{'bib_hits'} = $stats->{'hits'};
+
     HIT: foreach my $hit (@{ $results->{'hit'} }) {
         my $recid = $hit->{recid}->[0];
 
@@ -655,7 +659,7 @@ sub pazGetRecords {
         for (my $i = 0; $i < $count; $i++) {
             # FIXME -- may need to worry about diacritics here
             my $rec = $paz->record($recid, $i);
-            push @{ $result_group->{'RECORDS'} }, $paz->record($recid, $i);
+            push @{ $result_group->{'RECORDS'} }, $rec;
         }
 
         push @{ $results_hashref->{'biblioserver'}->{'GROUPS'} }, $result_group;
index a3d326f..f35a113 100755 (executable)
@@ -335,7 +335,10 @@ for (my $i=0;$i<=@servers;$i++) {
         my @newresults;
         if ($build_grouped_results) {
             foreach my $group (@{ $results_hashref->{$server}->{"GROUPS"} }) {
-                my @group_results = searchResults( $query_desc, $group->{'group_count'},$results_per_page,$offset, 
+                # because pazGetRecords handles retieving only the records
+                # we want as specified by $offset and $results_per_page,
+                # we need to set the offset parameter of searchResults to 0
+                my @group_results = searchResults( $query_desc, $group->{'group_count'},$results_per_page, 0,
                                                    @{ $group->{"RECORDS"} });
                 push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
             }