From: Bill Erickson Date: Tue, 30 Oct 2018 15:07:04 +0000 (-0400) Subject: search_format filter; logging X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=057077c53940742934b6572e2d24b60d74c43de1;p=working%2FEvergreen.git search_format filter; logging Signed-off-by: Bill Erickson --- 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 cc28349418..35da1d86db 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm @@ -39,6 +39,8 @@ my %org_data_cache = (by_shortname => {}, ancestors_at => {}); sub bib_search { my ($class, $query, $staff, $offset, $limit) = @_; + $logger->info("ES parsing API query $query"); + $bib_search_fields = new_editor()->retrieve_all_elastic_bib_field() unless $bib_search_fields; @@ -54,12 +56,11 @@ sub bib_search { $es->connect; my $results = $es->search($elastic_query); - $logger->info("ES elasticsearch returned: ". + $logger->debug("ES elasticsearch returned: ". OpenSRF::Utils::JSON->perl2JSON($results)); return {count => 0} unless $results; - return { count => $results->{hits}->{total}, ids => [ @@ -112,35 +113,27 @@ sub translate_elastic_query { # Remove unsupported tags (e.g. #deleted) $query =~ s/\#[a-z]+//ig; - my @funcs = qw/site depth sort item_lang/; + my @funcs = qw/site depth sort item_lang format/; my %calls; for my $func (@funcs) { my ($val) = ($query =~ /$func\(([^\)]+)\)/); + if (defined $val) { - # scrub from query string - $query =~ s/$func\(([^\)]+)\)//g; + $query =~ s/$func\(([^\)]+)\)//g; # scrub $calls{$func} = $val; } } - my @facets = ($query =~ /([a-z]+\|[a-z]+\[[^\]]+\])/g); - - if (@facets) { - # scrub the query of facets - $query =~ s/([a-z]+\|[a-z]+\[[^\]]+\])//g; - } - + $query =~ s/([a-z]+\|[a-z]+\[[^\]]+\])//g if @facets; # scrub my $cache_seed = "$query $staff $available "; - # TODO: confirm matches @funcs above where needed - for my $key (qw/site depth item_lang/) { + for my $key (qw/site depth item_lang format/) { $cache_seed .= " $key=" . $calls{$key} if defined $calls{$key}; } my $cache_key = md5_hex($cache_seed); - $logger->info("ES cache seed = $cache_seed | $cache_key"); my $elastic_query = { _source => ['id'], # Fetch bib ID only @@ -161,6 +154,12 @@ sub translate_elastic_query { } }; + if ($calls{format}) { + push( + @{$elastic_query->{query}->{bool}->{filter}}, + {term => {search_format => $calls{format}}} + ); + } add_elastic_facet_filters($elastic_query, @facets); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm b/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm index 5f53fef276..b30a1c2cb8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm @@ -128,7 +128,7 @@ sub connect { $server->proto, $server->host, $server->port)); } - $logger->info("ES connecting to nodes @nodes"); + $logger->debug("ES connecting to nodes @nodes"); eval { $self->{es} = Search::Elasticsearch->new(nodes => \@nodes) };