From 2616e00c167857ddd4e76eb402111bd5abca7fce Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 9 Sep 2019 17:15:49 -0400 Subject: [PATCH] misc tidying and docs Signed-off-by: Bill Erickson --- .../src/eg2/src/app/share/catalog/elastic.service.ts | 13 +++++++++---- .../perlmods/lib/OpenILS/Application/Search/Elastic.pm | 16 +++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts index 000f16d3a6..bee44035ad 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts @@ -94,11 +94,16 @@ export class ElasticService { addSort(ctx: CatalogSearchContext, search: RequestBodySearch) { - if (!ctx.sort) { return; } + if (ctx.sort) { // e.g. title, title.descending - // e.g. title, title.descending - const parts = ctx.sort.split(/\./); - search.sort(new Sort(parts[0], parts[1] ? 'desc' : 'asc')); + const parts = ctx.sort.split(/\./); + search.sort(new Sort(parts[0], parts[1] ? 'desc' : 'asc')); + + } else { + + // Sort by match score by default. + search.sort(new Sort('_score', 'asc')); + } } addFilters(ctx: CatalogSearchContext, rootNode: BoolQuery) { 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 144c4ce379..da51d3e9eb 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm @@ -162,6 +162,8 @@ sub bib_search { $logger->info("ES parsing API query $query staff=$staff"); + return {count => 0, ids => []} unless $query && $query->{query}; + my $elastic_query = compile_elastic_query($query, $options, $staff); my $es = OpenILS::Elastic::BibSearch->new('main'); @@ -196,10 +198,18 @@ sub bib_search { sub compile_elastic_query { my ($elastic, $options, $staff) = @_; + # We require a boolean root node to collect all the other stuff. + $elastic->{query}->{bool} = {must => $elastic->{query}} + unless $elastic->{query}->{bool}; + # coerce the filter into an array so we can append to it. - $elastic->{filter} = [] unless $elastic->{filter}; - $elastic->{filter} = [$elastic->{filter}] - unless ref $elastic->{filter} eq 'ARRAY'; + my $filters = $elastic->{query}->{bool}->{filter}; + if ($filters) { + $elastic->{query}->{bool}->{filter} = [$filters] + unless ref $filters eq 'ARRAY'; + } else { + $elastic->{query}->{bool}->{filter} = []; + } add_elastic_holdings_filter($elastic, $staff, $options->{search_org}, $options->{search_depth}, $options->{available}); -- 2.11.0