Lines 568-573
sub get_components_query {
Link Here
|
568 |
return $searchstr; |
568 |
return $searchstr; |
569 |
} |
569 |
} |
570 |
|
570 |
|
|
|
571 |
=head3 get_marc_volumes |
572 |
|
573 |
my $volumes = $self->get_marc_volumes(); |
574 |
|
575 |
Returns an array of MARCXML data, which are volumes parts of |
576 |
this object (MARC21 773$w points to this) |
577 |
|
578 |
=cut |
579 |
|
580 |
sub get_marc_volumes { |
581 |
my ( $self, $max_results ) = @_; |
582 |
|
583 |
return $self->{_volumes} if defined( $self->{_volumes} ); |
584 |
|
585 |
my $searchstr = $self->get_volumes_query; |
586 |
|
587 |
if ( defined($searchstr) ) { |
588 |
my $searcher = Koha::SearchEngine::Search->new( |
589 |
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
590 |
my ( $errors, $results, $total_hits ) = |
591 |
$searcher->simple_search_compat( $searchstr, 0, $max_results ); |
592 |
$self->{_volumes} = |
593 |
( defined($results) && scalar(@$results) ) ? $results : []; |
594 |
} |
595 |
else { |
596 |
$self->{_volumes} = []; |
597 |
} |
598 |
|
599 |
return $self->{_volumes}; |
600 |
} |
601 |
|
602 |
=head2 get_volumes_query |
603 |
|
604 |
Returns a query which can be used to search for all component parts of MARC21 biblios |
605 |
|
606 |
=cut |
607 |
|
608 |
sub get_volumes_query { |
609 |
my ($self) = @_; |
610 |
|
611 |
# MARC21 Only for now |
612 |
return if (C4::Context->preference('marcflavour') ne 'MARC21'); |
613 |
|
614 |
my $marc = $self->metadata->record; |
615 |
|
616 |
# Only build volumes query if we're in a 'Set' record |
617 |
# or we have a monographic series. |
618 |
my $leader19 = substr( $marc->leader, 19, 1 ); |
619 |
my $pf008 = $marc->field('008') || ''; |
620 |
my $mseries = ( $pf008 && substr( $pf008->data(), 21, 1 ) eq 'm' ) ? 1 : 0; |
621 |
return unless ( $leader19 eq 'a' || $mseries ); |
622 |
|
623 |
my $builder = Koha::SearchEngine::QueryBuilder->new( |
624 |
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
625 |
|
626 |
my $searchstr; |
627 |
if ( C4::Context->preference('UseControlNumber') ) { |
628 |
my $pf001 = $marc->field('001') || undef; |
629 |
|
630 |
if ( defined($pf001) ) { |
631 |
$searchstr = "("; |
632 |
my $pf003 = $marc->field('003') || undef; |
633 |
|
634 |
if ( !defined($pf003) ) { |
635 |
# search for 773$w='Host001' |
636 |
$searchstr .= "rcn:" . $pf001->data(); |
637 |
} |
638 |
else { |
639 |
$searchstr .= "("; |
640 |
# search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' |
641 |
$searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")"; |
642 |
$searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; |
643 |
$searchstr .= ")"; |
644 |
} |
645 |
|
646 |
# exclude monograph and serial component part records |
647 |
$searchstr .= " NOT (bib-level:a OR bib-level:b)"; |
648 |
$searchstr .= ")"; |
649 |
} |
650 |
} |
651 |
else { |
652 |
my $cleaned_title = $marc->subfield('245', "a"); |
653 |
$cleaned_title =~ tr|/||; |
654 |
$cleaned_title = $builder->clean_search_term($cleaned_title); |
655 |
$searchstr = "ti,phr:($cleaned_title)"; |
656 |
} |
657 |
|
658 |
return $searchstr; |
659 |
} |
660 |
|
571 |
=head3 subscriptions |
661 |
=head3 subscriptions |
572 |
|
662 |
|
573 |
my $subscriptions = $self->subscriptions |
663 |
my $subscriptions = $self->subscriptions |
Lines 1034-1112
sub get_marc_host {
Link Here
|
1034 |
} |
1124 |
} |
1035 |
} |
1125 |
} |
1036 |
|
1126 |
|
1037 |
=head3 get_marc_volumes |
|
|
1038 |
|
1039 |
my $volumes = $self->get_marc_volumes(); |
1040 |
|
1041 |
Returns an array of MARCXML data, which are volumes parts of |
1042 |
this object (MARC21 773$w points to this) |
1043 |
|
1044 |
=cut |
1045 |
|
1046 |
sub get_marc_volumes { |
1047 |
my ($self, $max_results) = @_; |
1048 |
|
1049 |
return [] if (C4::Context->preference('marcflavour') ne 'MARC21'); |
1050 |
|
1051 |
my $searchstr = $self->get_volumes_query; |
1052 |
|
1053 |
if (defined($searchstr)) { |
1054 |
my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); |
1055 |
my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat( $searchstr, 0, $max_results ); |
1056 |
$self->{_volumes} = $results if ( defined($results) && scalar(@$results) ); |
1057 |
} |
1058 |
|
1059 |
return $self->{_volumes} || []; |
1060 |
} |
1061 |
|
1062 |
=head2 get_volumes_query |
1063 |
|
1064 |
Returns a query which can be used to search for all component parts of MARC21 biblios |
1065 |
|
1066 |
=cut |
1067 |
|
1068 |
sub get_volumes_query { |
1069 |
my ($self) = @_; |
1070 |
|
1071 |
my $builder = Koha::SearchEngine::QueryBuilder->new( |
1072 |
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
1073 |
my $marc = $self->metadata->record; |
1074 |
|
1075 |
my $searchstr; |
1076 |
if ( C4::Context->preference('UseControlNumber') ) { |
1077 |
my $pf001 = $marc->field('001') || undef; |
1078 |
|
1079 |
if ( defined($pf001) ) { |
1080 |
$searchstr = "("; |
1081 |
my $pf003 = $marc->field('003') || undef; |
1082 |
|
1083 |
if ( !defined($pf003) ) { |
1084 |
# search for 773$w='Host001' |
1085 |
$searchstr .= "rcn:" . $pf001->data(); |
1086 |
} |
1087 |
else { |
1088 |
$searchstr .= "("; |
1089 |
# search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' |
1090 |
$searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")"; |
1091 |
$searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; |
1092 |
$searchstr .= ")"; |
1093 |
} |
1094 |
|
1095 |
# exclude monograph and serial component part records |
1096 |
$searchstr .= " NOT (bib-level:a OR bib-level:b)"; |
1097 |
$searchstr .= ")"; |
1098 |
} |
1099 |
} |
1100 |
else { |
1101 |
my $cleaned_title = $marc->subfield('245', "a"); |
1102 |
$cleaned_title =~ tr|/||; |
1103 |
$cleaned_title = $builder->clean_search_term($cleaned_title); |
1104 |
$searchstr = "ti,phr:($cleaned_title)"; |
1105 |
} |
1106 |
|
1107 |
return $searchstr; |
1108 |
} |
1109 |
|
1110 |
=head2 Internal methods |
1127 |
=head2 Internal methods |
1111 |
|
1128 |
|
1112 |
=head3 type |
1129 |
=head3 type |