From be61c6558d94b6b28a411ff0c1a48e03b2027a2c Mon Sep 17 00:00:00 2001 From: tipaul Date: Fri, 27 Apr 2007 19:57:12 +0000 Subject: [PATCH] koha NZ speed improvement for title ordering --- C4/Search.pm | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 72001b54ad..e8cca04c87 100755 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1065,7 +1065,7 @@ sub NZgetRecords { my $result = NZanalyse($koha_query); # use Data::Dumper; # warn "==========".@$sort_by_ref[0]; - return (undef,NZorder($result,@$sort_by_ref[0]),undef); + return (undef,NZorder($result,@$sort_by_ref[0],$results_per_page,$offset),undef); } =item @@ -1204,9 +1204,11 @@ sub NZanalyse { } sub NZorder { - my ($biblionumbers, $ordering) = @_; + my ($biblionumbers, $ordering,$results_per_page,$offset) = @_; # order title asc by default $ordering = '1=36 dbh; # # order by POPULARITY @@ -1347,24 +1349,33 @@ sub NZorder { } else { # the title is in the biblionumbers string, so we just need to build a hash, sort it and return my %result; +# splice(@X,$results_per_page*(1+$offset)); +# splice(@X,0,$results_per_page*$offset); foreach (split /,/,$biblionumbers) { my ($biblionumber,$title) = split /;/,$_; # hint : the result is sorted by title.biblionumber because we can have X biblios with the same title # and we don't want to get only 1 result for each of them !!! - $result{$title.$biblionumber}=GetMarcBiblio($biblionumber); + # hint & speed improvement : we can order without reading the record + # so order, and read records only for the requested page ! + $result{$title.$biblionumber}=$biblionumber; } # sort the hash and return the same structure as GetRecords (Zebra querying) my $result_hash; my $numbers=0; if ($ordering eq '1=36 {'RECORDS'}[$numbers++] = $result{$key}->as_usmarc(); + $result_hash->{'RECORDS'}[$numbers++] = $result{$key}; } } else { # sort by title ASC foreach my $key (sort { $a <=> $b } (keys %result)) { - $result_hash->{'RECORDS'}[$numbers++] = $result{$key}->as_usmarc(); + $result_hash->{'RECORDS'}[$numbers++] = $result{$key}; } } + # for the requested page, replace biblionumber by the complete record + # speed improvement : avoid reading too much things + for (my $counter=$offset;$counter<=$offset+$results_per_page;$counter++) { + $result_hash->{'RECORDS'}[$counter] = GetMarcBiblio($result_hash->{'RECORDS'}[$counter])->as_usmarc; + } my $finalresult=(); $result_hash->{'hits'} = $numbers; $finalresult->{'biblioserver'} = $result_hash; -- 2.20.1