Bug 22339: Fix search field mappings of MARC fixed fields
authorEre Maijala <ere.maijala@helsinki.fi>
Thu, 14 Mar 2019 11:31:34 +0000 (13:31 +0200)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 26 Apr 2019 15:20:48 +0000 (16:20 +0100)
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 <bjorn.nylen@ub.lu.se>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 0047ede37e46a3334c9c47d7ebaed848907b6890)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/SearchEngine/Elasticsearch.pm
admin/searchengine/elasticsearch/mappings.yaml
installer/data/mysql/atomicupdate/bug_22339.perl [new file with mode: 0644]
t/Koha/SearchEngine/Elasticsearch.t

index ff7aba6..8613f8c 100644 (file)
@@ -597,8 +597,8 @@ An optional range as a string in the format "<START>-<END>" or "<START>",
 where "<START>" and "<END>" 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 "<START>" is provided only one character at position "<START>" will
 be extracted.
@@ -613,7 +613,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];
index 5cb2c18..7a0bf42 100644 (file)
@@ -1756,12 +1756,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: ''
@@ -1867,12 +1867,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: ''
@@ -1881,12 +1881,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: ''
@@ -1895,12 +1895,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: ''
@@ -1909,12 +1909,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: ''
@@ -2581,12 +2581,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 (file)
index 0000000..187e936
--- /dev/null
@@ -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";
+}
index 1fe3ad1..4954179 100644 (file)
@@ -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');