View | Details | Raw Unified | Return to bug 23089
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch.pm (-1 / +1 lines)
Lines 228-234 sub get_elasticsearch_mappings { Link Here
228
                # Sort is a bit special as it can be true, false, undef.
228
                # Sort is a bit special as it can be true, false, undef.
229
                # We care about "true" or "undef",
229
                # We care about "true" or "undef",
230
                # "undef" means to do the default thing, which is make it sortable.
230
                # "undef" means to do the default thing, which is make it sortable.
231
                if (!defined $sort || $sort) {
231
                if (!defined $sort || $sort && $es_type ne 'integer') {
232
                    $mappings->{data}{properties}{ $name . '__sort' } = _get_elasticsearch_field_config('sort', $es_type);
232
                    $mappings->{data}{properties}{ $name . '__sort' } = _get_elasticsearch_field_config('sort', $es_type);
233
                    $sort_fields{$self->index}{$name} = 1;
233
                    $sort_fields{$self->index}{$name} = 1;
234
                }
234
                }
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-5 / +4 lines)
Lines 912-927 sub _sort_field { Link Here
912
    my ($self, $f) = @_;
912
    my ($self, $f) = @_;
913
913
914
    my $mappings = $self->get_elasticsearch_mappings();
914
    my $mappings = $self->get_elasticsearch_mappings();
915
    my $textField = defined $mappings->{data}{properties}{$f}{type} && $mappings->{data}{properties}{$f}{type} eq 'text';
915
    my $fieldType = defined $mappings->{data}{properties}{$f}{type} ? $mappings->{data}{properties}{$f}{type} : undef;
916
    if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) {
916
    if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) {
917
        $f .= '__sort';
917
        $f .= '__sort' unless $fieldType eq 'integer';
918
        # We need to add '.phrase' to text fields, otherwise it'll sort
918
        # We need to add '.phrase' to text fields, otherwise it'll sort
919
        # based on the tokenised form.
919
        # based on the tokenised form.
920
        $f .= '.phrase' if $textField;
920
        $f .= '.phrase' if $fieldType eq 'text';
921
    } else {
921
    } else {
922
        # We need to add '.raw' to text fields without a sort field,
922
        # We need to add '.raw' to text fields without a sort field,
923
        # otherwise it'll sort based on the tokenised form.
923
        # otherwise it'll sort based on the tokenised form.
924
        $f .= '.raw' if $textField;
924
        $f .= '.raw' if $fieldType eq 'text';
925
    }
925
    }
926
    return $f;
926
    return $f;
927
}
927
}
928
- 

Return to bug 23089