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

(-)a/C4/Heading.pm (-1 / +16 lines)
Lines 233-239 sub _search { Link Here
233
        \@value,    $self->{'auth_type'},
233
        \@value,    $self->{'auth_type'},
234
        'AuthidAsc'
234
        'AuthidAsc'
235
    );
235
    );
236
    return $searcher->search_auth_compat( $search_query, 0, 20, $skipmetadata );
236
237
    my ( $matched_auths, $total ) = $searcher->search_auth_compat( $search_query, 0, 20, $skipmetadata );
238
    # Some auth records may not contain the 040$f to specify their source
239
    # This is legal, so we do a fallback search
240
    if( !$total && $thesaurus && !( grep /$thesaurus/,('lcsh','lcac','mesh','nal','notspecified','cash','rvm','sears','aat') ) ){
241
        pop @value;
242
        push @value, 'z';
243
        $search_query = $builder->build_authorities_query_compat(
244
            \@marclist, \@and_or, \@excluding, \@operator,
245
            \@value,    $self->{'auth_type'},
246
            'AuthidAsc'
247
        );
248
        ( $matched_auths, $total ) = $searcher->search_auth_compat( $search_query, 0, 20, $skipmetadata );
249
    }
250
    return ( $matched_auths, $total );
251
237
}
252
}
238
253
239
=head1 INTERNAL FUNCTIONS
254
=head1 INTERNAL FUNCTIONS
(-)a/t/db_dependent/Heading.t (-9 / +28 lines)
Lines 65-71 subtest "UNIMARC tests" => sub { Link Here
65
65
66
subtest "_search tests" => sub {
66
subtest "_search tests" => sub {
67
67
68
    plan tests => 6;
68
    plan tests => 7;
69
69
70
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
70
    t::lib::Mocks::mock_preference('marcflavour', 'MARC21');
71
    t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch');
71
    t::lib::Mocks::mock_preference('SearchEngine', 'Elasticsearch');
Lines 74-86 subtest "_search tests" => sub { Link Here
74
    $search->mock('search_auth_compat', sub {
74
    $search->mock('search_auth_compat', sub {
75
        my $self = shift;
75
        my $self = shift;
76
        my $search_query = shift;
76
        my $search_query = shift;
77
        return $search_query;
77
        return ($search_query, 1 );
78
    });
78
    });
79
79
80
80
81
    my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
81
    my $field = MARC::Field->new( '650', ' ', '0', a => 'Uncles', x => 'Fiction' );
82
    my $heading = C4::Heading->new_from_field($field);
82
    my $heading = C4::Heading->new_from_field($field);
83
    my $search_query = $heading->_search( 'match-heading' );
83
    my ($search_query) = $heading->_search( 'match-heading' );
84
    my $terms = $search_query->{query}->{bool}->{must};
84
    my $terms = $search_query->{query}->{bool}->{must};
85
    my $expected_terms = [
85
    my $expected_terms = [
86
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
86
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
Lines 90-96 subtest "_search tests" => sub { Link Here
90
90
91
    $field = MARC::Field->new( '650', ' ', '3', a => 'Uncles', x => 'Fiction' );
91
    $field = MARC::Field->new( '650', ' ', '3', a => 'Uncles', x => 'Fiction' );
92
    $heading = C4::Heading->new_from_field($field);
92
    $heading = C4::Heading->new_from_field($field);
93
    $search_query = $heading->_search( 'match-heading' );
93
    ($search_query) = $heading->_search( 'match-heading' );
94
    $terms = $search_query->{query}->{bool}->{must};
94
    $terms = $search_query->{query}->{bool}->{must};
95
    $expected_terms = [
95
    $expected_terms = [
96
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
96
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
Lines 100-106 subtest "_search tests" => sub { Link Here
100
100
101
    $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' );
101
    $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' );
102
    $heading = C4::Heading->new_from_field($field);
102
    $heading = C4::Heading->new_from_field($field);
103
    $search_query = $heading->_search( 'match-heading' );
103
    ($search_query) = $heading->_search( 'match-heading' );
104
    $terms = $search_query->{query}->{bool}->{must};
104
    $terms = $search_query->{query}->{bool}->{must};
105
    $expected_terms = [
105
    $expected_terms = [
106
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
106
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
Lines 110-116 subtest "_search tests" => sub { Link Here
110
110
111
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,' );
111
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,' );
112
    $heading = C4::Heading->new_from_field($field);
112
    $heading = C4::Heading->new_from_field($field);
113
    $search_query = $heading->_search( 'match-heading' );
113
    ($search_query) = $heading->_search( 'match-heading' );
114
    $terms = $search_query->{query}->{bool}->{must};
114
    $terms = $search_query->{query}->{bool}->{must};
115
    $expected_terms = [
115
    $expected_terms = [
116
        { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } },
116
        { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } },
Lines 119-125 subtest "_search tests" => sub { Link Here
119
119
120
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' );
120
    $field = MARC::Field->new( '100', ' ', '', a => 'Yankovic, Al', d => '1959-,', e => '[author]' );
121
    $heading = C4::Heading->new_from_field($field);
121
    $heading = C4::Heading->new_from_field($field);
122
    $search_query = $heading->_search( 'match-heading' );
122
    ($search_query) = $heading->_search( 'match-heading' );
123
    $terms = $search_query->{query}->{bool}->{must};
123
    $terms = $search_query->{query}->{bool}->{must};
124
    $expected_terms = [
124
    $expected_terms = [
125
        { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } },
125
        { term => { 'match-heading.ci_raw' => 'Yankovic, Al 1959' } },
Lines 128-138 subtest "_search tests" => sub { Link Here
128
128
129
    $field = MARC::Field->new( '100', ' ', '', a => 'Tolkien, J.R.R.,', e => '[author]' );
129
    $field = MARC::Field->new( '100', ' ', '', a => 'Tolkien, J.R.R.,', e => '[author]' );
130
    $heading = C4::Heading->new_from_field($field);
130
    $heading = C4::Heading->new_from_field($field);
131
    $search_query = $heading->_search( 'match-heading' );
131
    ($search_query) = $heading->_search( 'match-heading' );
132
    $terms = $search_query->{query}->{bool}->{must};
132
    $terms = $search_query->{query}->{bool}->{must};
133
    $expected_terms = [
133
    $expected_terms = [
134
        { term => { 'match-heading.ci_raw' => 'Tolkien, J.R.R' } },
134
        { term => { 'match-heading.ci_raw' => 'Tolkien, J.R.R' } },
135
    ];
135
    ];
136
    is_deeply( $terms, $expected_terms, "Search formed as expected for a non-subject field with double punctuation, period+comma ");
136
    is_deeply( $terms, $expected_terms, "Search formed as expected for a non-subject field with double punctuation, period+comma ");
137
137
138
    $search->mock('search_auth_compat', sub {
139
        my $self = shift;
140
        my $search_query = shift;
141
        if( $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq 'special_sauce' ){
142
            return;
143
        }
144
        return ($search_query, 1);
145
    });
146
147
    # Special case where thesaurus defined in subfield 2 should also match record with no thesaurus
148
    $field = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' );
149
    $heading = C4::Heading->new_from_field($field);
150
    ($search_query) = $heading->_search( 'match-heading' );
151
    $terms = $search_query->{query}->{bool}->{must};
152
    $expected_terms = [
153
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
154
        { term => { 'subject-heading-thesaurus.ci_raw' => 'z' } },
155
    ];
156
    is_deeply( $terms, $expected_terms, "When thesaurus in subfield 2, and nothing is found, we should search again for 008_11 = z");
157
138
};
158
};
139
- 

Return to bug 33277