misc tidying and docs
authorBill Erickson <berickxx@gmail.com>
Mon, 9 Sep 2019 21:15:49 +0000 (17:15 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 22 Oct 2019 13:18:21 +0000 (09:18 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts
Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Elastic.pm

index 000f16d..bee4403 100644 (file)
@@ -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) {
index 144c4ce..da51d3e 100644 (file)
@@ -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});