From 7c20263fd0930997a8da70b8798e0ada623ac2bc Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 23 Apr 2024 18:57:54 +0000 Subject: [PATCH] Bug 36678: Index fields with non-filing characters in both versions Currently we only remove non-filing characters for sort fields, however, this can make searching difficult. This patch adds the filing form to the index as well to aid in searching. To test: 0 - Setup Koha with Elasticsearch 1 - Import the sample record on this report: "L'amour de l'art" 2 - Search for "amour de l'art" - no results 3 - Apply patch 4 - Reindex 5 - Search for "amour de l'art" - result! 6 - Search for "title:amour de l'art" - result! Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- Koha/SearchEngine/Elasticsearch.pm | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index fc7ef4d789..5989e8ce4f 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -520,7 +520,13 @@ sub _process_mappings { $nonfiling_chars = looks_like_number($nonfiling_chars) ? int($nonfiling_chars) : 0; # Nonfiling chars does not make sense for multiple values # Only apply on first element - $values->[0] = substr $values->[0], $nonfiling_chars; + if ( $nonfiling_chars > 0 ) { + if ($sort) { + $values->[0] = substr $values->[0], $nonfiling_chars; + } else { + push @{$values}, substr $values->[0], $nonfiling_chars; + } + } } $values = [ grep(!/^$/, @{$values}) ]; @@ -1196,12 +1202,10 @@ sub _get_marc_mapping_rules { foreach my $indicator (keys %title_fields) { foreach my $field_tag (@{$title_fields{$indicator}}) { my $mappings = $rules->{data_fields}->{$field_tag}->{subfields}->{a} // []; - foreach my $mapping (@{$mappings}) { - if ($mapping->[0] =~ /__sort$/) { - # Mark this as to be processed for nonfiling characters indicator - # later on in _process_mappings - $mapping->[1]->{nonfiling_characters_indicator} = $indicator; - } + foreach my $mapping ( @{$mappings} ) { + # Mark this as to be processed for nonfiling characters indicator + # later on in _process_mappings + $mapping->[1]->{nonfiling_characters_indicator} = $indicator; } } } -- 2.39.5