View | Details | Raw Unified | Return to bug 35117
Collapse All | Expand All

(-)a/Koha/Biblio.pm (-14 / +17 lines)
Lines 669-680 Returns a query which can be used to search for all component parts of MARC21 bi Link Here
669
sub get_components_query {
669
sub get_components_query {
670
    my ($self) = @_;
670
    my ($self) = @_;
671
671
672
    my $builder = Koha::SearchEngine::QueryBuilder->new(
672
    # MARC21 Only for now
673
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
673
    return if ( C4::Context->preference('marcflavour') ne 'MARC21' );
674
674
    my $marc = $self->metadata->record;
675
    my $marc = $self->metadata->record;
676
677
    my $builder              = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
675
    my $component_sort_field = C4::Context->preference('ComponentSortField') // "title";
678
    my $component_sort_field = C4::Context->preference('ComponentSortField') // "title";
676
    my $component_sort_order = C4::Context->preference('ComponentSortOrder') // "asc";
679
    my $component_sort_order = C4::Context->preference('ComponentSortOrder') // "asc";
677
    my $sort = $component_sort_field . "_" . $component_sort_order;
680
    my $sort                 = $component_sort_field . "_" . $component_sort_order;
678
681
679
    my $searchstr;
682
    my $searchstr;
680
    if ( C4::Context->preference('UseControlNumber') ) {
683
    if ( C4::Context->preference('UseControlNumber') ) {
Lines 685-695 sub get_components_query { Link Here
685
            my $pf003 = $marc->field('003') || undef;
688
            my $pf003 = $marc->field('003') || undef;
686
689
687
            if ( !defined($pf003) ) {
690
            if ( !defined($pf003) ) {
691
688
                # search for 773$w='Host001'
692
                # search for 773$w='Host001'
689
                $searchstr .= "rcn:\"" . $pf001->data()."\"";
693
                $searchstr .= "rcn:\"" . $pf001->data() . "\"";
690
            }
694
            } else {
691
            else {
692
                $searchstr .= "(";
695
                $searchstr .= "(";
696
693
                # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001'
697
                # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001'
694
                $searchstr .= "(rcn:\"" . $pf001->data() . "\" AND cni:\"" . $pf003->data() . "\")";
698
                $searchstr .= "(rcn:\"" . $pf001->data() . "\" AND cni:\"" . $pf003->data() . "\")";
695
                $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\"";
699
                $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\"";
Lines 700-719 sub get_components_query { Link Here
700
            $searchstr .= " AND (bib-level:a OR bib-level:b)";
704
            $searchstr .= " AND (bib-level:a OR bib-level:b)";
701
            $searchstr .= ")";
705
            $searchstr .= ")";
702
        }
706
        }
703
    }
707
    } else {
704
    else {
708
        my $cleaned_title = $marc->subfield( '245', "a" );
705
        my $cleaned_title = $marc->subfield('245', "a");
706
        $cleaned_title =~ tr|/||;
709
        $cleaned_title =~ tr|/||;
707
        $cleaned_title = $builder->clean_search_term($cleaned_title);
710
        $cleaned_title = $builder->clean_search_term($cleaned_title);
708
        $searchstr = qq#Host-item:("$cleaned_title")#;
711
        $searchstr     = qq#Host-item:("$cleaned_title")#;
712
        $searchstr .= " AND (bib-level:a OR bib-level:b)";
709
    }
713
    }
710
    my ($error, $query ,$query_str) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 );
714
    my ( $error, $query, $query_str ) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 );
711
    if( $error ){
715
    if ($error) {
712
        warn $error;
716
        warn $error;
713
        return;
717
        return;
714
    }
718
    }
715
719
716
    return ($query, $query_str, $sort);
720
    return ( $query, $query_str, $sort );
717
}
721
}
718
722
719
=head3 get_marc_volumes
723
=head3 get_marc_volumes
720
- 

Return to bug 35117