From 0047ede37e46a3334c9c47d7ebaed848907b6890 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Thu, 14 Mar 2019 13:31:34 +0200 Subject: [PATCH] Bug 22339: Fix search field mappings of MARC fixed fields MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes handling of /0 selector in addition to several fixed field positions. Note that ff7-01-02 is in fact 00-01 in Zebra and that has been replicated here. Test plan: 1. Before applying a patch, check from Elasticsearch (e.g. localhost:9200/koha_biblios/_search?q=_id:123) what is indexed in Elasticsearch for a record for date-entered-on-file, ff7-00, ff7-01, ff7-02 and lleader. 2. Apply the patch, update database and save the record again. 3. Verify that the contents of the forementioned fields is now correct in Elasticsearch. 4. Verify that tests pass: prove -v t/Koha/SearchEngine/Elasticsearch.t Signed-off-by: Björn Nylén Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/SearchEngine/Elasticsearch.pm | 6 +- .../searchengine/elasticsearch/mappings.yaml | 24 ++++---- .../data/mysql/atomicupdate/bug_22339.perl | 55 +++++++++++++++++++ t/Koha/SearchEngine/Elasticsearch.t | 14 ++++- 4 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_22339.perl diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 92453488da..b46537d112 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -610,8 +610,8 @@ An optional range as a string in the format "-" or "", where "" and "" are integers specifying a range that will be used for extracting a substring from MARC data as Elasticsearch field target value. -The first character position is "1", and the range is inclusive, -so "1-3" means the first three characters of MARC data. +The first character position is "0", and the range is inclusive, +so "0-2" means the first three characters of MARC data. If only "" is provided only one character at position "" will be extracted. @@ -626,7 +626,7 @@ sub _field_mappings { my @mappings; my $substr_args = undef; - if ($range) { + if (defined $range) { # TODO: use value_callback instead? my ($start, $end) = map(int, split /-/, $range, 2); $substr_args = [$start]; diff --git a/admin/searchengine/elasticsearch/mappings.yaml b/admin/searchengine/elasticsearch/mappings.yaml index 8ead46bd59..a546c341e6 100644 --- a/admin/searchengine/elasticsearch/mappings.yaml +++ b/admin/searchengine/elasticsearch/mappings.yaml @@ -1758,12 +1758,12 @@ biblios: label: date-entered-on-file mappings: - facet: '' - marc_field: '008_/1-5' + marc_field: '008_/0-5' marc_type: marc21 sort: ~ suggestible: '' - facet: '' - marc_field: '008_/1-5' + marc_field: '008_/0-5' marc_type: normarc sort: ~ suggestible: '' @@ -1869,12 +1869,12 @@ biblios: label: ff7-00 mappings: - facet: '' - marc_field: 007_/1 + marc_field: 007_/0 marc_type: marc21 sort: ~ suggestible: '' - facet: '' - marc_field: 007_/1 + marc_field: 007_/0 marc_type: normarc sort: ~ suggestible: '' @@ -1883,12 +1883,12 @@ biblios: label: ff7-01 mappings: - facet: '' - marc_field: 007_/2 + marc_field: 007_/1 marc_type: marc21 sort: ~ suggestible: '' - facet: '' - marc_field: 007_/2 + marc_field: 007_/1 marc_type: normarc sort: ~ suggestible: '' @@ -1897,12 +1897,12 @@ biblios: label: ff7-01-02 mappings: - facet: '' - marc_field: 007_/1-2 + marc_field: 007_/0-1 marc_type: marc21 sort: ~ suggestible: '' - facet: '' - marc_field: 007_/1-2 + marc_field: 007_/0-1 marc_type: normarc sort: ~ suggestible: '' @@ -1911,12 +1911,12 @@ biblios: label: ff7-02 mappings: - facet: '' - marc_field: 007_/3 + marc_field: 007_/2 marc_type: marc21 sort: ~ suggestible: '' - facet: '' - marc_field: 007_/3 + marc_field: 007_/2 marc_type: normarc sort: ~ suggestible: '' @@ -2586,12 +2586,12 @@ biblios: label: llength mappings: - facet: '' - marc_field: leader_/1-5 + marc_field: leader_/0-4 marc_type: marc21 sort: ~ suggestible: '' - facet: '' - marc_field: leader_/1-5 + marc_field: leader_/0-4 marc_type: normarc sort: ~ suggestible: '' diff --git a/installer/data/mysql/atomicupdate/bug_22339.perl b/installer/data/mysql/atomicupdate/bug_22339.perl new file mode 100644 index 0000000000..187e936c74 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_22339.perl @@ -0,0 +1,55 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + $dbh->do( q| + UPDATE search_marc_map SET marc_field='007_/0' + WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/1' AND id IN + (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN + (SELECT id FROM search_field WHERE label='ff7-00') + ) + |); + + $dbh->do( q| + UPDATE search_marc_map SET marc_field='007_/1' + WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/2' AND id IN + (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN + (SELECT id FROM search_field WHERE label='ff7-01') + ) + |); + + $dbh->do( q| + UPDATE search_marc_map SET marc_field='007_/2' + WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/3' AND id IN + (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN + (SELECT id FROM search_field WHERE label='ff7-02') + ) + |); + + # N.B. ff7-01-02 really is 00-01! + $dbh->do( q| + UPDATE search_marc_map SET marc_field='007_/0-1' + WHERE marc_type IN ('marc21', 'normarc') AND marc_field='007_/1-2' AND id IN + (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN + (SELECT id FROM search_field WHERE label='ff7-01-02') + ) + |); + + $dbh->do( q| + UPDATE search_marc_map SET marc_field='008_/0-5' + WHERE marc_type IN ('marc21', 'normarc') AND marc_field='008_/1-5' AND id IN + (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN + (SELECT id FROM search_field WHERE label='date-entered-on-file') + ) + |); + + $dbh->do( q| + UPDATE search_marc_map SET marc_field='leader_/0-4' + WHERE marc_type IN ('marc21', 'normarc') AND marc_field='leader_/1-5' AND id IN + (SELECT search_marc_map_id FROM search_marc_to_field WHERE search_field_id IN + (SELECT id FROM search_field WHERE label='llength') + ) + |); + + # Always end with this (adjust the bug info) + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 22339 - Fix search field mappings of MARC fixed fields)\n"; +} diff --git a/t/Koha/SearchEngine/Elasticsearch.t b/t/Koha/SearchEngine/Elasticsearch.t index 1fe3ad14e1..4954179e51 100644 --- a/t/Koha/SearchEngine/Elasticsearch.t +++ b/t/Koha/SearchEngine/Elasticsearch.t @@ -117,7 +117,7 @@ subtest 'get_elasticsearch_mappings() tests' => sub { subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub { - plan tests => 49; + plan tests => 50; t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); @@ -239,6 +239,15 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' marc_type => 'marc21', marc_field => 'leader_/6-7', }, + { + name => 'ff7-00', + type => 'string', + facet => 0, + suggestible => 0, + sort => 0, + marc_type => 'marc21', + marc_field => '007_/0', + }, ); my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); @@ -268,6 +277,7 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' $marc_record_1->leader(' cam 22 a 4500'); $marc_record_1->append_fields( MARC::Field->new('001', '123'), + MARC::Field->new('007', 'ku'), MARC::Field->new('020', '', '', a => '1-56619-909-3'), MARC::Field->new('100', '', '', a => 'Author 1'), MARC::Field->new('110', '', '', a => 'Corp Author'), @@ -301,6 +311,8 @@ subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' is_deeply($docs->[0][1]->{control_number}, ['123'], 'First record control number should be set correctly'); + is_deeply($docs->[0][1]->{'ff7-00'}, ['k'], 'First record ff7-00 should be set correctly'); + is(scalar @{$docs->[0][1]->{author}}, 2, 'First document author field should contain two values'); is_deeply($docs->[0][1]->{author}, ['Author 1', 'Corp Author'], 'First document author field should be set correctly'); -- 2.39.5