From 904da739837d2f887e8bba609bd9dc9507b961ce Mon Sep 17 00:00:00 2001 From: miker Date: Sun, 10 Aug 2008 05:34:55 +0000 Subject: [PATCH] more staged search configurability and acuracy git-svn-id: svn://svn.open-ils.org/ILS/trunk@10320 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Search/Biblio.pm | 31 +++++++++++++++++-- .../Application/Storage/Publisher/metabib.pm | 2 +- .../src/sql/Pg/300.schema.staged_search.sql | 2 +- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm index ac2faf9196..09ebf4fe1e 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Search/Biblio.pm @@ -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}, diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm index f89961a403..ab681bcd16 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/metabib.pm @@ -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, diff --git a/Open-ILS/src/sql/Pg/300.schema.staged_search.sql b/Open-ILS/src/sql/Pg/300.schema.staged_search.sql index 8014426eec..158e16170b 100644 --- a/Open-ILS/src/sql/Pg/300.schema.staged_search.sql +++ b/Open-ILS/src/sql/Pg/300.schema.staged_search.sql @@ -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 -- 2.43.2