LP1844418 Direct indexing WIP
authorBill Erickson <berickxx@gmail.com>
Mon, 24 Feb 2020 17:07:23 +0000 (12:07 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 24 Feb 2020 17:07:23 +0000 (12:07 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm
Open-ILS/src/support-scripts/test-scripts/elastic-search-samples.pl
Open-ILS/src/support-scripts/test-scripts/elastic-search.pl

index c8cc731..316520a 100644 (file)
@@ -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 {
index c45e7c4..1202ce4 100755 (executable)
@@ -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 <<HELP;
         Synopsis:
 
-            $0
+            $0 --index-name <name>
 
         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) {
 
index 6882434..c0ffda6 100755 (executable)
@@ -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 <<HELP;
         Synopsis:
 
-            $0
+            $0 --index-name <name>
 
         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 <<MESSAGE;
 
 Enter a query string to perform a search. Ctrl-c to exit.