more staged search configurability and acuracy
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 10 Aug 2008 05:34:55 +0000 (05:34 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Sun, 10 Aug 2008 05:34:55 +0000 (05:34 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@10320 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm
Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm
Open-ILS/src/sql/Pg/300.schema.staged_search.sql

index ac2faf9..09ebf4f 100644 (file)
@@ -781,11 +781,12 @@ sub staged_search {
     $search_hash->{core_limit} = $superpage_size * $max_superpages;
 
     # Set the configured estimation strategy, defaults to 'inclusion'.
-       $search_hash->{estimation_strategy} = OpenSRF::Utils::SettingsClient
+       my $estimation_strategy = OpenSRF::Utils::SettingsClient
         ->new
         ->config_value(
             apps => 'open-ils.search', app_settings => 'estimation_strategy'
-        );
+        ) || 'inclusion';
+       $search_hash->{estimation_strategy} = $estimation_strategy;
 
     # pull any existing results from the cache
     my $key = search_cache_key($method, $search_hash);
@@ -797,6 +798,7 @@ sub staged_search {
     my $page; # current superpage
     my $est_hit_count = 0;
     my $current_page_summary = {};
+    my $global_summary = {checked => 0, visible => 0, excluded => 0, deleted => 0, total => 0};
 
     for($page = 0; $page < $max_superpages; $page++) {
 
@@ -845,6 +847,14 @@ sub staged_search {
         $logger->debug("staged search: located $current_count, with estimated hits=".
             $summary->{estimated_hit_count}." : visible=".$summary->{visible}.", checked=".$summary->{checked});
 
+               if (defined($summary->{estimated_hit_count})) {
+                       $global_summary->{checked} += $summary->{checked};
+                       $global_summary->{visible} += $summary->{visible};
+                       $global_summary->{excluded} += $summary->{excluded};
+                       $global_summary->{deleted} += $summary->{deleted};
+                       $global_summary->{total} = $summary->{total};
+               }
+
         # we've found all the possible hits
         last if $current_count == $summary->{visible}
             and not defined $summary->{estimated_hit_count};
@@ -858,6 +868,23 @@ sub staged_search {
 
     my @results = grep {defined $_} @$all_results[$user_offset..($user_offset + $user_limit - 1)];
 
+       # refine the estimate if we have more than one superpage
+       if ($page > 0) {
+               if ($global_summary->{checked} >= $global_summary->{total}) {
+                       $est_hit_count = $global_summary->{visible};
+               } else {
+                       my $updated_hit_count = $U->storagereq(
+                               'open-ils.storage.fts_paging_estimate',
+                               $global_summary->{checked},
+                               $global_summary->{visible},
+                               $global_summary->{excluded},
+                               $global_summary->{deleted},
+                               $global_summary->{total}
+                       );
+                       $est_hit_count = $updated_hit_count->{$estimation_strategy};
+               }
+       }
+
     return {
         count => $est_hit_count,
         core_limit => $search_hash->{core_limit},
index f89961a..ab681bc 100644 (file)
@@ -2652,7 +2652,7 @@ sub FTS_paging_estimate {
 }
 __PACKAGE__->register_method(
        api_name        => "open-ils.storage.fts_paging_estimate",
-       method          => 'staged_fts',
+       method          => 'FTS_paging_estimate',
     argc        => 5,
     strict      => 1,
        api_level       => 1,
index 8014426..158e161 100644 (file)
@@ -258,7 +258,7 @@ BEGIN
         tmp_text := '999999';
         IF param_sort_desc THEN tmp_text := '0'; END IF;
 
-        current_rank := $$ COALESCE( mrd.date1, $$ || quote_literal(tmp_text) || $$ )::INT ) $$;
+        current_rank := $$ COALESCE( FIRST(NULLIF(REGEXP_REPLACE(mrd.date1, E'\\D+', '9', 'g'),'')), $$ || quote_literal(tmp_text) || $$ )::INT $$;
 
     ELSIF param_sort = 'title' THEN