From 491732aeef515dd48c5aa11c92127fdeb296596d Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 11 Sep 2019 11:58:10 -0400 Subject: [PATCH] boost and score sorting repairs Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts | 2 +- Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm | 10 +++++++--- Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm | 12 ++++++++---- Open-ILS/src/support-scripts/test-scripts/elastic-search.pl | 7 ++----- 4 files changed, 18 insertions(+), 13 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 cdc2b46f35..3ef62081d7 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 @@ -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')); } } diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm b/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm index b4d8f732e7..d049630d4a 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Elastic.pm @@ -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) }; diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm index e002b93313..9a08ecce7b 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Elastic/Bib/Search.pm @@ -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)); diff --git a/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl b/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl index 9cfdcf9dc8..a49a909909 100755 --- a/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl +++ b/Open-ILS/src/support-scripts/test-scripts/elastic-search.pl @@ -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 => [{ -- 2.11.0