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 {
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;
'help' => \$help,
'osrf-config=s' => \$osrf_config,
'cluster=s' => \$cluster,
+ 'index-name=s' => \$index_name,
'quiet' => \$quiet,
) || die "\nSee --help for more\n";
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);
}
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) {
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;
'help' => \$help,
'osrf-config=s' => \$osrf_config,
'cluster=s' => \$cluster,
+ 'index-name=s' => \$index_name,
'quiet' => \$quiet,
) || die "\nSee --help for more\n";
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);
}
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.