$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
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();
});
$hidden_copy_locations = [map {$_->{id}} @$locs];
+
+ return 1;
}
# Translate a bib search API call into something consumable by Elasticsearch
$logger->info("ES parsing API query $query staff=$staff");
- init_data();
-
my ($elastic_query, $cache_key) =
compile_elastic_query($query, $staff, $offset, $limit);