[Koha-bugs] [Bug 3191] New: Bug in NonZebra search functions SimpleSearch() and NZOrder()
bugzilla-daemon at liblime.com
bugzilla-daemon at liblime.com
Wed May 6 11:10:51 CEST 2009
http://bugs.koha.org/cgi-bin/bugzilla3/show_bug.cgi?id=3191
Summary: Bug in NonZebra search functions SimpleSearch() and
NZOrder()
Product: Koha
Version: rel_3_0
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P5
Component: Searching
AssignedTo: jmf at liblime.com
ReportedBy: abcendzone at yahoo.com
Estimated Hours: 0.0
Bug 1)
The NonZebra SimpleSearch() function in C4::Search.pm has the following two
inputs:
- $offset: is the offset when displaying e.g. page 2 of the search results
- $max_results: is the maximal number of results per page
Bug: These two input parameters are NOT passed on to the NZorder() funtion on
line 223 when using nonzebra search:
Instead of:
my $result = NZorder( NZanalyse($query) )->{'biblioserver'};
this line should pass $offset and $max_results like this:
my $result = NZorder( NZanalyse($query),,$max_results,$offset
)->{'biblioserver'};
Bug 2)
The NonZebra NZOrder() function is supposed to order the search results and
return ($results_per_page) entries starting from ($offset). The code that is
supposed to do this (starting at around line 2059 in Search.pm) looks like
this:
# for (
# my $counter = $offset ;
# $counter <= $offset + $results_per_page ;
# $counter++
# )
# {
# $result_hash->{'RECORDS'}[$counter] =
# GetMarcBiblio( $result_hash->{'RECORDS'}[$counter]
)->as_usmarc;
# #if $result_hash->{'RECORDS'}[$counter];
# }
# my $finalresult = ();
# $result_hash->{'hits'} = $numbers;
# $finalresult->{'biblioserver'} = $result_hash;
# return $finalresult;
But this code actually returns an array of size ($numbers), which is the TOTAL
number of search results and within this array, it ONLY populates the entries
from ($offset) up to ($offset + $results_per_page).
So,
1. the array is way too big,
2. t has mostly empty elements
3. it returns one results too much, because from ($offset) up to ($offset+
$results_per_page) are a total of ($results_per_page+1) elements
What is SHOULD do is return an array of size ($results_per_page), containing
exactly ($results_per_page) search results from ($offset) up to ($offset +
$results_per_page - 1).
The correct code would be something like this:
my $finalresult = (); #create output array
$finalresult->{'biblioserver'}->{'hits'} = $numbers; #save total number
of search results
$numbers=0; #reset counter
for (
my $counter = $offset ;
$counter < $offset + $results_per_page ; #changed <= to < to
return correct number of elements
$counter++
)
{
$finalresult->{'biblioserver'}->{'RECORDS'}[$numbers++] =
GetMarcBiblio( $result_hash->{'RECORDS'}[$counter] )->as_usmarc;
#populate the array from 0 to ($results_per_page-1) with the search
results from ($offset) to ($offset+$results_per_page-1)
}
return $finalresult;
The buggy code is used TWICE in NZOrder() in Search.pm, so it has to be
replaced starting from line 2059 and starting from line 2113.
Best regards...
--
Configure bugmail: http://bugs.koha.org/cgi-bin/bugzilla3/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.
More information about the Koha-bugs
mailing list