Browse Source

Bug 23089: Fix sorting on sum and regular fields

As of bug 20589 we no longer analyze sort fields and so we no longer need to append ".phrase"
to our sort in searches.

Additionally, sort fields based on 'sum' should also use sum in building the value to sort on

To test:
0 - Be using ES
1 - Find the most circulated item in your collection
2 - Search for '*'
3 - Sort by popularity DESC
4 - Note that item is not first
5 - Try to sort by anything but relevancy, it fails
6 - Apply patch
7 - Redo searches and sorts
8 - Things should now work as expected

Signed-off-by: Ere Maijala <ere.maijala@helsinki.fi>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
remotes/origin/19.11.x
Nick Clemens 2 years ago
committed by Martin Renvoize
parent
commit
6a2ba8b6b2
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 1
      Koha/SearchEngine/Elasticsearch.pm
  2. 3
      Koha/SearchEngine/Elasticsearch/QueryBuilder.pm
  3. 1
      admin/searchengine/elasticsearch/field_config.yaml

1
Koha/SearchEngine/Elasticsearch.pm

@ -831,6 +831,7 @@ sub _get_marc_mapping_rules {
if ($type eq 'sum') {
push @{$rules->{sum}}, $name;
push @{$rules->{sum}}, $name."__sort" if $sort;
}
elsif ($type eq 'isbn') {
push @{$rules->{isbn}}, $name;

3
Koha/SearchEngine/Elasticsearch/QueryBuilder.pm

@ -992,9 +992,6 @@ sub _sort_field {
my $textField = defined $mappings->{data}{properties}{$f}{type} && $mappings->{data}{properties}{$f}{type} eq 'text';
if (!defined $self->sort_fields()->{$f} || $self->sort_fields()->{$f}) {
$f .= '__sort';
# We need to add '.phrase' to text fields, otherwise it'll sort
# based on the tokenised form.
$f .= '.phrase' if $textField;
} else {
# We need to add '.raw' to text fields without a sort field,
# otherwise it'll sort based on the tokenised form.

1
admin/searchengine/elasticsearch/field_config.yaml

@ -65,3 +65,4 @@ sort:
default:
type: icu_collation_keyword
index: false
numeric: true
Loading…
Cancel
Save