Bugzilla – Attachment 110002 Details for
Bug 24807
Add "year" type to improve sorting by publication date
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24807: Simplify with new and imporved value_callbacks
Bug-24807-Simplify-with-new-and-imporved-valuecall.patch (text/plain), 4.75 KB, created by
Katrin Fischer
on 2020-09-12 22:30:45 UTC
(
hide
)
Description:
Bug 24807: Simplify with new and imporved value_callbacks
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2020-09-12 22:30:45 UTC
Size:
4.75 KB
patch
obsolete
>From bf73e58d812b3ba0f508d756d5d228d93168f643 Mon Sep 17 00:00:00 2001 >From: David Gustafsson <glasklas@gmail.com> >Date: Mon, 20 Apr 2020 13:03:24 +0200 >Subject: [PATCH] Bug 24807: Simplify with new and imporved value_callbacks > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > Koha/SearchEngine/Elasticsearch.pm | 60 +++++++++++++------------------------- > 1 file changed, 20 insertions(+), 40 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index c4dce5501a..674e375ec2 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -477,50 +477,38 @@ sub _process_mappings { > $data_copy = length($data) > $start ? substr $data_copy, $start, $length : ''; > } > >- # Add data to tokens array for callbacks processing >- my $tokens = [$data_copy]; >- >- # Tokenize callbacks takes as token (possibly tokenized subfield data) >- # as argument, and returns a possibly different list of tokens. >- # Note that this list also might be empty. >- if (defined $options->{tokenize_callbacks}) { >- foreach my $callback (@{$options->{tokenize_callbacks}}) { >- # Pass each token to current callback which returns a list >+ # Add data to values array for callbacks processing >+ my $values = [$data_copy]; >+ >+ # Value callbacks takes subfield data (or values from previous >+ # callbacks) as argument, and returns a possibly different list of values. >+ # Note that the returned list may also be empty. >+ if (defined $options->{value_callbacks}) { >+ foreach my $callback (@{$options->{value_callbacks}}) { >+ # Pass each value to current callback which returns a list > # (scalar is fine too) resulting either in a list or > # a list of lists that will be flattened by perl. >- # The next callback will recieve the possibly expanded list of tokens. >- $tokens = [ map { $callback->($_) } @{$tokens} ]; >- } >- } >- if (defined $options->{value_callbacks}) { >- $tokens = [ map { reduce { $b->($a) } ($_, @{$options->{value_callbacks}}) } @{$tokens} ]; >- } >- if (defined $options->{filter_callbacks}) { >- my @tokens_filtered; >- foreach my $_data (@{$tokens}) { >- if ( all { $_->($_data) } @{$options->{filter_callbacks}} ) { >- push @tokens_filtered, $_data; >- } >+ # The next callback will recieve the possibly expanded list of values. >+ $values = [ map { $callback->($_) } @{$values} ]; > } >- # Overwrite $tokens with filtered values >- $tokens = \@tokens_filtered; > } >+ > # Skip mapping if all values has been removed >- next unless @{$tokens}; >+ next unless @{$values}; > > if (defined $options->{property}) { >- $tokens = [ map { { $options->{property} => $_ } } @{$tokens} ]; >+ $values = [ map { { $options->{property} => $_ } } @{$values} ]; > } > if (defined $options->{nonfiling_characters_indicator}) { > my $nonfiling_chars = $meta->{field}->indicator($options->{nonfiling_characters_indicator}); > $nonfiling_chars = looks_like_number($nonfiling_chars) ? int($nonfiling_chars) : 0; >- # Nonfiling chars does not make sense for multiple tokens >+ # Nonfiling chars does not make sense for multiple values > # Only apply on first element >- $tokens->[0] = substr $tokens->[0], $nonfiling_chars; >+ $values->[0] = substr $values->[0], $nonfiling_chars; > } > > $record_document->{$target} //= []; >- push @{$record_document->{$target}}, @{$tokens}; >+ push @{$record_document->{$target}}, @{$values}; > } > } > >@@ -916,20 +904,12 @@ sub _field_mappings { > }; > } > elsif ($target_type eq 'year') { >- $default_options->{tokenize_callbacks} //= []; >- # Only accept years containing digits and "u" >- push @{$default_options->{tokenize_callbacks}}, sub { >- my ($value) = @_; >- my @years = ( $value =~ /[0-9u]{4}/g ); >- return @years; >- }; >- > $default_options->{value_callbacks} //= []; >- # Replace "u" with "0" for sorting >+ # Only accept years containing digits and "u" > push @{$default_options->{value_callbacks}}, sub { > my ($value) = @_; >- $value =~ s/[u]/0/g; >- return $value; >+ # Replace "u" with "0" for sorting >+ return map { s/[u]/0/gr } ( $value =~ /[0-9u]{4}/g ); > }; > } > >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24807
:
100170
|
100171
|
100176
|
102547
|
102548
|
103084
|
103085
|
103086
|
103087
|
103163
|
103277
|
104525
|
104526
|
104527
|
104528
|
104529
|
104530
|
104531
|
106768
|
108382
|
108383
|
108384
|
108385
|
108386
|
108387
|
108388
|
108389
|
109997
|
109998
|
109999
|
110000
|
110001
| 110002 |
110003
|
110004
|
110355
|
110884