boost and score sorting repairs
authorBill Erickson <berickxx@gmail.com>
Wed, 11 Sep 2019 15:58:10 +0000 (11:58 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 13 Jun 2022 20:01:54 +0000 (16:01 -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/Elastic.pm
Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm
Open-ILS/src/support-scripts/test-scripts/elastic-search.pl

index cdc2b46..3ef6208 100644 (file)
@@ -112,7 +112,7 @@ export class ElasticService {
         } else {
             
             // Sort by match score by default.
-            search.sort(new Sort('_score', 'asc'));
+            search.sort(new Sort('_score', 'desc'));
         }
     }
 
index b4d8f73..d049630 100644 (file)
@@ -131,11 +131,15 @@ sub connect {
 
     my @nodes;
     for my $server (@{$self->nodes}) {
-        push(@nodes, sprintf("%s://%s:%d%s", 
-            $server->proto, $server->host, $server->port, $server->path));
+        push(@nodes, {
+            scheme => $server->proto,
+            host   => $server->host,
+            port   => $server->port,
+            path   => $server->path
+        });
     }
 
-    $logger->debug("ES connecting to nodes @nodes");
+    $logger->debug("ES connecting to ".scalar(@nodes)." nodes");
 
     eval { $self->{es} = Search::Elasticsearch->new(nodes => \@nodes) };
 
index e002b93..9a08ecc 100644 (file)
@@ -147,7 +147,7 @@ sub create_index {
         if ($field->search_field eq 't') {
             # Text search fields get an additional variety of indexes to
             # support full text searching
-
+        
             $fields->{text} = {type => 'text'},
             $fields->{text_folded} = {type => 'text', analyzer => 'folding'};
 
@@ -158,13 +158,17 @@ sub create_index {
                     analyzer => $lang_analyzer
                 };
             }
+
+            if ((my $boost = ($field->weight || 1)) > 1) {
+                $fields->{text}->{boost} = $boost;
+                $fields->{text_folded}->{boost} = $boost;
+                $fields->{"text_$_"}->{boost} = $boost 
+                    foreach $self->language_analyzers;
+            }
         }
 
         $def->{fields} = $fields if keys %$fields;
 
-        # Apply field boost.
-        $def->{boost} = $field->weight if ($field->weight || 1) > 1;
-
         $logger->debug("ES adding field $field_name: ". 
             OpenSRF::Utils::JSON->perl2JSON($def));
 
index 9cfdcf9..a49a909 100755 (executable)
@@ -43,13 +43,10 @@ OpenILS::Utils::CStoreEditor::init();
 
 # Title search AND subject search AND MARC tag=100 search
 my $query = {
-  _source => ['id', 'title|proper'] , # return only the ID field
+  _source => ['id', 'title|maintitle'] , # return only the ID field
   from => 0,
   size => 5,
-  sort => [
-    {'titlesort' => 'asc'},
-    '_score'
-  ],
+  sort => [{'_score' => 'desc'}],
   query => {
     bool => {
       must => [{