From 97daa07286ea2436c92e9af71a880fca33fe34f6 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 6 Nov 2018 10:20:02 -0500 Subject: [PATCH] ES gets child init Signed-off-by: Bill Erickson --- .../src/perlmods/lib/OpenILS/Application/Search.pm | 1 + .../lib/OpenILS/Application/Search/Biblio.pm | 15 ++++------- .../lib/OpenILS/Application/Search/Elastic.pm | 30 +++++++++++++++++++--- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search.pm index 78d4a4e2db..bcd3fbfad5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search.pm @@ -36,6 +36,7 @@ sub initialize { sub child_init { OpenILS::Application::Search::Z3950->child_init; OpenILS::Application::Search::Browse->child_init; + OpenILS::Application::Search::Elastic->child_init; } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm index ce75bed2a0..a0ac123bfd 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Biblio.pm @@ -1157,16 +1157,11 @@ sub staged_search { $user_offset = ($user_offset >= 0) ? $user_offset : 0; $user_limit = ($user_limit >= 0) ? $user_limit : 10; - # TODO: cache this. Real-time lookups are better for testing, though. - my $use_elastic = new_editor()->search_elastic_index({ - active => 't', code => 'bib-search'})->[0]; - - if ($use_elastic) { - return OpenILS::Application::Search::Elastic->bib_search( - $search_hash->{query}, ($method =~ /staff/ ? 1 : 0), - $user_offset, $user_limit - ); - } + return OpenILS::Application::Search::Elastic->bib_search( + $search_hash->{query}, # query string + ($method =~ /staff/ ? 1 : 0), + $user_offset, $user_limit + ) if OpenILS::Application::Search::Elastic->is_enabled; # we're grabbing results on a per-superpage basis, which means the # limit and offset should coincide with superpage boundaries diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm index e311658324..bb6caa14a5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm @@ -39,9 +39,31 @@ my $bib_fields; my $hidden_copy_statuses; my $hidden_copy_locations; my $avail_copy_statuses; +our $enabled = undef; -sub init_data { - return if $bib_fields; +# Returns true if the Elasticsearch 'bib-search' index is active. +sub is_enabled { + + return $enabled if defined $enabled; + + # Elastic bib search is enabled if a "bib-search" index is enabled. + my $index = new_editor()->search_elastic_index( + {active => 't', code => 'bib-search'})->[0]; + + if ($index) { + + $logger->info("ES bib-search index is enabled"); + $enabled = 1; + } else { + $enabled = 0; + } + + return $enabled; +} + +sub child_init { + my $class = shift; + return unless $class->is_enabled(); my $e = new_editor(); @@ -70,6 +92,8 @@ sub init_data { }); $hidden_copy_locations = [map {$_->{id}} @$locs]; + + return 1; } # Translate a bib search API call into something consumable by Elasticsearch @@ -80,8 +104,6 @@ sub bib_search { $logger->info("ES parsing API query $query staff=$staff"); - init_data(); - my ($elastic_query, $cache_key) = compile_elastic_query($query, $staff, $offset, $limit); -- 2.11.0