From c2fe68dda45cb16f2671f0cd7fb87e7d0d579018 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 24 Feb 2020 12:07:23 -0500 Subject: [PATCH] LP1844418 Direct indexing WIP Signed-off-by: Bill Erickson --- Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm | 40 ++++++++++++++++++++-- .../test-scripts/elastic-search-samples.pl | 18 ++++++++-- .../support-scripts/test-scripts/elastic-search.pl | 17 +++++++-- 3 files changed, 67 insertions(+), 8 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm b/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm index c8cc731659..316520a7f6 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm @@ -134,12 +134,48 @@ sub load_config { return; } - $self->{indices} = $e->search_elastic_index({cluster => $cluster, %active}); + if (!$self->index_class) { + $logger->error("ES index_class required to initialize"); + return; + } + + $self->{indices} = $e->search_elastic_index({ + cluster => $cluster, + index_class => $self->index_class, + %active + }); + + if ($self->write_mode) { - unless ($self->write_mode || @{$self->indices}) { + if (!$self->index_name) { + $logger->error("ES index_name required for write mode"); + return; + } + + return; + } + + # read-only mode + + if (!@{$self->indices}) { $logger->warn("ES no active indices defined for cluster $cluster"); return; } + + if (!$self->index_name) { + # In non-write mode, if no index name is provided, default + # to using the active index on the current index class. + + my ($index) = grep { + $_->index_class eq $self->index_class && $_->active eq 't' + } @{$self->{indices}}; + + if ($index) { + my $name = $index->name; + $logger->info("ES no index_name specificed, defaulting to $name"); + $self->{index_name} = $name; + } + } } sub find_index_config { diff --git a/Open-ILS/src/support-scripts/test-scripts/elastic-search-samples.pl b/Open-ILS/src/support-scripts/test-scripts/elastic-search-samples.pl index c45e7c4d07..1202ce4d5b 100755 --- a/Open-ILS/src/support-scripts/test-scripts/elastic-search-samples.pl +++ b/Open-ILS/src/support-scripts/test-scripts/elastic-search-samples.pl @@ -14,7 +14,8 @@ binmode(STDOUT, ':utf8'); my $help; my $osrf_config = '/openils/conf/opensrf_core.xml'; my $cluster = 'main'; -my $index = 'bib-search'; +my $index_class = 'bib-search'; +my $index_name; my $quiet = 0; my $query_string; @@ -22,6 +23,7 @@ GetOptions( 'help' => \$help, 'osrf-config=s' => \$osrf_config, 'cluster=s' => \$cluster, + 'index-name=s' => \$index_name, 'quiet' => \$quiet, ) || die "\nSee --help for more\n"; @@ -29,10 +31,13 @@ sub help { print < Performs a series of canned bib record searches + Note if --index-name is omitted, the currently active index on + the 'bib-search' index class will be used. + HELP exit(0); } @@ -117,9 +122,16 @@ Fieldmapper->import( IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); OpenILS::Utils::CStoreEditor::init(); -my $es = OpenILS::Elastic::BibSearch->new($cluster); +my $es = OpenILS::Elastic::BibSearch->new(index_name => $index_name); $es->connect; +if ($es->index_name) { + print "Using bib-search index '" . $es->index_name . "'\n"; +} else { + die "No active 'bib-search' index found. ". + "Use --index-name or activate an index in the database.\n"; +} + print "Searching...\n"; for my $query_part (@$queries) { diff --git a/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl b/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl index 6882434375..c0ffda6af6 100755 --- a/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl +++ b/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl @@ -14,7 +14,7 @@ binmode(STDOUT, ':utf8'); my $help; my $osrf_config = '/openils/conf/opensrf_core.xml'; my $cluster = 'main'; -my $index = 'bib-search'; +my $index_name; my $quiet = 0; my $query_string; @@ -22,6 +22,7 @@ GetOptions( 'help' => \$help, 'osrf-config=s' => \$osrf_config, 'cluster=s' => \$cluster, + 'index-name=s' => \$index_name, 'quiet' => \$quiet, ) || die "\nSee --help for more\n"; @@ -29,10 +30,13 @@ sub help { print < Performs query string searches. + Note if --index-name is omitted, the currently active index on + the 'bib-search' index class will be used. + HELP exit(0); } @@ -46,9 +50,16 @@ Fieldmapper->import( IDL => OpenSRF::Utils::SettingsClient->new->config_value("IDL")); OpenILS::Utils::CStoreEditor::init(); -my $es = OpenILS::Elastic::BibSearch->new; +my $es = OpenILS::Elastic::BibSearch->new(index_name => $index_name); $es->connect; +if ($es->index_name) { + print "Using bib-search index '" . $es->index_name . "'\n"; +} else { + die "No active 'bib-search' index found. ". + "Use --index-name or activate an index in the database.\n"; +} + print <