From 4cae9b49f3036c8500db702d031c8475f5fb673b Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 8 Apr 2020 09:55:20 +0000 Subject: [PATCH] Bug 24807: Add suppport for uncertain fields and ranges To test: 1 - Have some records with uncertain dates in the 008 19uu, 195u, etc. 2 - Index them in Elasticsearch 3 - Do a search that will return them 4 - Sort results by publication/copyright date 5 - Note odd results 6 - Apply patch 7 - Reindex 8 - Sorting should be improved Signed-off-by: Nick Clemens Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart --- Koha/SearchEngine/Elasticsearch.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 1a8d3aa72b..aabf719e73 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -481,7 +481,7 @@ sub _process_mappings { } if (defined $options->{filter_callbacks}) { # Skip mapping unless all filter callbacks return true - next unless all { $_->($_data) } @{$options->{filter_callbacks}}; + next unless all { $_data = $_->($_data) } @{$options->{filter_callbacks}}; } if (defined $options->{property}) { $_data = { @@ -497,7 +497,11 @@ sub _process_mappings { } $record_document->{$target} //= []; - push @{$record_document->{$target}}, $_data; + if( ref $_data eq 'ARRAY' ){ + push @{$record_document->{$target}}, @{$_data}; + } else { + push @{$record_document->{$target}}, $_data; + } } } @@ -896,7 +900,13 @@ sub _field_mappings { $default_options->{filter_callbacks} //= []; push @{$default_options->{filter_callbacks}}, sub { my ($value) = @_; - return $value =~ /^\d+$/; + my @years = (); + my @field_years = ( $value =~ /[0-9u]{4}/g ); + foreach my $year (@field_years){ + $year =~ s/[u]/0/g; + push @years, $year; + } + return \@years; }; } -- 2.39.5