From 340e2da40b0938235f0f0e3e3226e3dbf1f9e610 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 13 Nov 2019 14:31:39 +0000 Subject: [PATCH] Bug 23089: [19.05 and earlier] Use integer field directly for sorting (cherry picked from commit 55ccf90711c103ac69e9b047110780453bc83d0a) --- Koha/SearchEngine/Elasticsearch.pm | 2 +- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 2c9f02359d..0a14e8d0b7 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -228,7 +228,7 @@ sub get_elasticsearch_mappings { # Sort is a bit special as it can be true, false, undef. # We care about "true" or "undef", # "undef" means to do the default thing, which is make it sortable. - if (!defined $sort || $sort) { + if (!defined $sort || $sort && $es_type ne 'integer') { $mappings->{data}{properties}{ $name . '__sort' } = _get_elasticsearch_field_config('sort', $es_type); $sort_fields{$self->index}{$name} = 1; } diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 96e7bf0dde..ee8cb6c6c8 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -907,16 +907,16 @@ sub _sort_field { my ($self, $f) = @_; my $mappings = $self->get_elasticsearch_mappings(); - my $textField = defined $mappings->{data}{properties}{$f}{type} && $mappings->{data}{properties}{$f}{type} eq 'text'; + my $fieldType = defined $mappings->{data}{properties}{$f}{type} ? $mappings->{data}{properties}{$f}{type} : undef; if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) { - $f .= '__sort'; + $f .= '__sort' unless $fieldType eq 'integer'; # We need to add '.phrase' to text fields, otherwise it'll sort # based on the tokenised form. - $f .= '.phrase' if $textField; + $f .= '.phrase' if $fieldType eq 'text'; } else { # We need to add '.raw' to text fields without a sort field, # otherwise it'll sort based on the tokenised form. - $f .= '.raw' if $textField; + $f .= '.raw' if $fieldType eq 'text'; } return $f; } -- 2.39.5