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>
(cherry picked from commit 6a2ba8b6b2)
Signed-off-by: Hayley Mapley <hayleymapley@catalyst.net.nz>
This commit is contained in:
Nick 2019-10-10 16:06:08 +00:00 committed by Hayley Mapley
parent b94ca526b8
commit 2b769cbc32
3 changed files with 5 additions and 10 deletions

View File

@ -699,6 +699,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;

View File

@ -909,10 +909,7 @@ sub _sort_field {
my $mappings = $self->get_elasticsearch_mappings();
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' unless $fieldType eq 'integer';
# We need to add '.phrase' to text fields, otherwise it'll sort
# based on the tokenised form.
$f .= '.phrase' if $fieldType eq 'text';
$f .= '__sort';
} else {
# We need to add '.raw' to text fields without a sort field,
# otherwise it'll sort based on the tokenised form.

View File

@ -64,9 +64,6 @@ suggestible:
# Sort
sort:
default:
type: text
analyzer: analyser_phrase
search_analyzer: analyser_phrase
fields:
phrase:
type: keyword
type: icu_collation_keyword
index: false
numeric: true