From 55ccf90711c103ac69e9b047110780453bc83d0a 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 --- 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 3b2b4ee08a..64ed46194b 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 7f0db644ae..63b9dbce7b 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -912,16 +912,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