Bug 33282: Remove useless intercept
[srvgit] / C4 / Heading.pm
index c58b507..7541a56 100644 (file)
@@ -19,11 +19,9 @@ package C4::Heading;
 
 use Modern::Perl;
 
-use MARC::Record;
 use MARC::Field;
 use C4::Context;
-use Module::Load;
-use Carp;
+use Module::Load qw( load );
 
 
 =head1 NAME
@@ -172,6 +170,8 @@ sub preferred_authorities {
 
     if (C4::Heading::valid_heading_subfield('100', 'e', '')) ...
 
+Check if the given subfield is valid for the given field.
+
 =cut
 
 sub valid_heading_subfield {
@@ -194,6 +194,8 @@ sub _search {
     my $self         = shift;
     my $index        = shift || undef;
     my $skipmetadata = shift || undef;
+    my $ind2         = $self->{field}->{_ind2};
+    my $subject_heading_thesaurus = '';
     my @marclist;
     my @and_or;
     my @excluding = [];
@@ -202,18 +204,43 @@ sub _search {
 
     if ($index) {
         push @marclist, $index;
-        push @and_or,   'and';
+        push @and_or,   'AND';
         push @operator, $self->{'match_type'};
         push @value,    $self->{'search_form'};
     }
 
-    #    if ($self->{'thesaurus'}) {
-    #        push @marclist, 'thesaurus';
-    #        push @and_or, 'and';
-    #        push @excluding, '';
-    #        push @operator, 'is';
-    #        push @value, $self->{'thesaurus'};
-    #    }
+    if ($self->{'thesaurus'}) {
+        if ($ind2 eq '0') {
+            $subject_heading_thesaurus = 'a';
+        } elsif ($ind2 eq '1') {
+            $subject_heading_thesaurus = 'b';
+        } elsif ($ind2 eq '2') {
+            $subject_heading_thesaurus = 'c';
+        } elsif ($ind2 eq '3') {
+            $subject_heading_thesaurus = 'd';
+        } elsif ($ind2 eq '4') {
+            $subject_heading_thesaurus = 'n';
+        } elsif ($ind2 eq '5') {
+            $subject_heading_thesaurus = 'k';
+        } elsif ($ind2 eq '6') {
+            $subject_heading_thesaurus = 'v';
+        } else {
+            $subject_heading_thesaurus = 'z';
+        }
+        push @marclist, 'thesaurus';
+        push @and_or, 'and';
+        push @excluding, '';
+        push @operator, 'is';
+        push @value, $subject_heading_thesaurus;
+    }
+
+    if ($ind2 eq '7') {
+        push @marclist, 'thesaurus-conventions';
+        push @and_or, 'and';
+        push @excluding, '';
+        push @operator, 'is';
+        push @value, $self->{'thesaurus'};
+    }
 
     require Koha::SearchEngine::QueryBuilder;
     require Koha::SearchEngine::Search;
@@ -245,7 +272,6 @@ depending on the selected MARC flavour.
 
 sub _marc_format_handler {
     my $marcflavour = uc shift;
-    $marcflavour = 'MARC21' if ( $marcflavour eq 'NORMARC' );
     my $pname = "C4::Heading::$marcflavour";
     load $pname;
     return $pname->new();