From 353175f30e80794eb18936497d5691d9869d9bab 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 --- 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 f575e95b08..34b6d0c807 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -482,7 +482,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 = { @@ -498,7 +498,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; + } } } @@ -893,7 +897,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.20.1