[open-ils-commits] r9017 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Search

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Mar 14 15:36:46 EDT 2008


Author: erickson
Date: 2008-03-14 15:03:06 -0400 (Fri, 14 Mar 2008)
New Revision: 9017

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
Log:
stop looking when we have checked all of the possible hits for visibility.  no longer calculating the average estimated hit count.  using the initial estimated hit count

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm	2008-03-14 17:38:39 UTC (rev 9016)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm	2008-03-14 19:03:06 UTC (rev 9017)
@@ -737,7 +737,7 @@
 	api_name	=> 'open-ils.search.metabib.multiclass.staged.staff',
 	signature	=> q/@see open-ils.search.biblio.multiclass.staged/);
 
-my $CHECK_SIZE = 1000;
+my $PAGE_SIZE = 1000;
 my $SEARCH_PAGES = 25;
 sub staged_search {
 	my($self, $conn, $search_hash, $nocache) = @_;
@@ -755,7 +755,8 @@
     # we're grabbing results on a per-superpage basis, which means the 
     # limit and offset should coincide with superpage boundaries
     $search_hash->{offset} = 0;
-    $search_hash->{limit} = $CHECK_SIZE;
+    $search_hash->{limit} = $PAGE_SIZE;
+    $search_hash->{check_limit} = $PAGE_SIZE; # force a well-known check_limit
 
     # pull any existing results from the cache
     my $key = search_cache_key($method, $search_hash);
@@ -764,8 +765,8 @@
     # keep retrieving results until we find enough to 
     # fulfill the user-specified limit and offset
     my $all_results = [];
-    my $avg_hit_count = 0;
     my $page; # current superpage
+    my $est_hit_count;
 
     for($page = 0; $page < $SEARCH_PAGES; $page++) {
 
@@ -784,7 +785,7 @@
         } else {
             # retrieve the window of results from the database
             $logger->debug("staged search: fetching results from the database");
-            $search_hash->{skip_check} = $page * $CHECK_SIZE;
+            $search_hash->{skip_check} = $page * $PAGE_SIZE;
             $results = $U->storagereq($method, %$search_hash);
             $summary = shift(@$results);
 
@@ -802,10 +803,12 @@
         push(@$all_results, grep {defined $_} @$results);
 
         my $current_count = scalar(@$all_results);
-        $avg_hit_count += $summary->{estimated_hit_count} || $summary->{visible};
 
+        $est_hit_count = $summary->{estimated_hit_count} || $summary->{visible}
+            if $page == 0;
+
         $logger->debug("staged search: located $current_count, with estimated hits=".
-            $summary->{estimated_hit_count}." : visible=".$summary->{visible});
+            $summary->{estimated_hit_count}." : visible=".$summary->{visible}.", checked=".$summary->{checked});
 
         # we've found all the possible hits
         last if $current_count == $summary->{visible}
@@ -813,16 +816,16 @@
 
         # we've found enough results to satisfy the requested limit/offset
         last if $current_count >= ($user_limit + $user_offset);
+
+        # we've scanned all possible hits
+        last if $summary->{checked} < $PAGE_SIZE;
     }
 
     # calculate the average estimated hit count from the data we've collected thus far
-    $avg_hit_count = int($avg_hit_count / ++$page);
-    $avg_hit_count = scalar(@$all_results) if scalar(@$all_results) > $avg_hit_count;
-
     my @results = grep {defined $_} @$all_results[$user_offset..($user_offset + $user_limit - 1)];
 
     return {
-        count => $avg_hit_count,
+        count => $est_hit_count,
         results => \@results
     };
 }



More information about the open-ils-commits mailing list