From 39dabfda3a38d7b4995341968fd80be0e79bd7ba Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 29 Sep 2016 16:08:36 +0100 Subject: [PATCH] Bug 17377: ES - Take control fields into account There is a bug in Koha::SearchEngine::Elasticsearc::Search->json2marc, it assumes that the MARC::Field constructor always takes >= 5 parameters. This assumption is wrong for control fields, to create a control field you need to call the constructor with: MARC::Field->new($tag, $value); Note that I got "Too much data for control field" in the _warning value of my MARC::Field because too many parameters were passed, and the value was undef. That broke the result search links (on the staff interface) for DB with biblio.biblionumber mapped with 001. Other bugs will certainly be fixed by this patch. For instance I got: GetMarcBiblio called with undefined biblionumber at /home/koha/src/opac/opac-search.pl line 664. GetCOinSBiblio called with undefined record at /home/koha/src/opac/opac-search.pl line 665. in my logs, with this patch I don't get them anymore. Test plan: You can try to recreate the different issues and confirm than this patch fixes them. Or just run the tests Signed-off-by: Nick Clemens --- Koha/SearchEngine/Elasticsearch/Search.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 9f14c3a..da54e57 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -358,14 +358,22 @@ sub json2marc { # fields are like: # [ '245', '1', '2', 'a' => 'Title', 'b' => 'Subtitle' ] + # or + # [ '001', undef, undef, '_', 'a value' ] # conveniently, this is the form that MARC::Field->new() likes foreach my $field (@$marcjson) { - next if @$field < 5; # Shouldn't be possible, but... + next if @$field < 5; if ( $field->[0] eq 'LDR' ) { $marc->leader( $field->[4] ); } else { - my $marc_field = MARC::Field->new(@$field); + my $tag = $field->[0]; + my $marc_field; + if ( MARC::Field->is_controlfield_tag( $field->[0] ) ) { + $marc_field = MARC::Field->new($field->[0], $field->[4]); + } else { + $marc_field = MARC::Field->new(@$field); + } $marc->append_fields($marc_field); } } -- 2.1.4