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

(-)a/t/db_dependent/Heading.t (-26 / +71 lines)
Lines 73-79 subtest "UNIMARC tests" => sub { Link Here
73
73
74
subtest "_search tests" => sub {
74
subtest "_search tests" => sub {
75
75
76
    plan tests => 10;
76
    plan tests => 11;
77
77
78
    t::lib::Mocks::mock_preference( 'marcflavour',  'MARC21' );
78
    t::lib::Mocks::mock_preference( 'marcflavour',  'MARC21' );
79
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' );
79
    t::lib::Mocks::mock_preference( 'SearchEngine', 'Elasticsearch' );
Lines 184-231 subtest "_search tests" => sub { Link Here
184
        "Search formed as expected for a non-subject field with double punctuation, period+comma "
184
        "Search formed as expected for a non-subject field with double punctuation, period+comma "
185
    );
185
    );
186
186
187
    # Special case where thesaurus defined in subfield 2 should also match record with no thesaurus
188
    # In the ES index an auth rec. without 040 $f, so 'z' from 008/11 is present in subject-heading-thesaurus
189
    my $expected_authid = 12345;
187
    $search->mock(
190
    $search->mock(
188
        'search_auth_compat',
191
        'search_auth_compat',
189
        sub {
192
        sub {
190
            my $self         = shift;
193
            my $self         = shift;
191
            my $search_query = shift;
194
            my $search_query = shift;
192
            if ( scalar @{ $search_query->{query}->{bool}->{must} } == 2
195
            if ( scalar @{ $search_query->{query}->{bool}->{must} } == 2 ) {
193
                && $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq
196
                if ( $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq
194
                'special_sauce' )
197
                    'special_sauce' )
195
            {
198
                {
196
                return;
199
                    # no record with 'special_sauce'
200
                    return ( [], 0 );
201
                } elsif (
202
                    $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq 'z' )
203
                {
204
                    # for 'notdefined' we return the only record with 008/11 = 'z'
205
                    return ( [ { authid => $expected_authid } ], 1 );
206
                } else {
207
208
                    # other cases - nothing
209
                    return ( [], 0 );
210
                }
211
            } elsif ( scalar @{ $search_query->{query}->{bool}->{must} } == 1 ) {
212
                return ['no thesaurus checking at all'];
197
            }
213
            }
198
            return ( $search_query, 1 );
199
        }
214
        }
200
    );
215
    );
201
202
    # Special case where thesaurus defined in subfield 2 should also match record with no thesaurus
203
    $field   = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' );
216
    $field   = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce' );
204
    $heading = C4::Heading->new_from_field($field);
217
    $heading = C4::Heading->new_from_field($field);
205
    ($search_query) = $heading->_search('match-heading');
218
    my ($matched_auths) = $heading->_search('match-heading');
206
    $terms          = $search_query->{query}->{bool}->{must};
219
    my $expected_result = [ { authid => $expected_authid } ];
207
    $expected_terms = [
208
        { term => { 'match-heading.ci_raw'             => 'Uncles generalsubdiv Fiction' } },
209
        { term => { 'subject-heading-thesaurus.ci_raw' => 'z' } },
210
    ];
211
    is_deeply(
220
    is_deeply(
212
        $terms, $expected_terms,
221
        $matched_auths, $expected_result,
213
        "When thesaurus in subfield 2, and nothing is found, we should search again for notdefined (008_11 = z) "
222
        "When thesaurus in subfield 2, we should search again for notdefined (008_11 = z) and get a result"
214
    );
223
    );
215
224
216
    t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' );
225
    # In the ES index an auth rec. with 040 $f 'special_sauce', so 'z' from 008/11 not present in subject-heading-thesaurus
226
    $search->mock(
227
        'search_auth_compat',
228
        sub {
229
            my $self         = shift;
230
            my $search_query = shift;
231
            if ( scalar @{ $search_query->{query}->{bool}->{must} } == 2 ) {
232
                if ( $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq
233
                    'special_sauce' )
234
                {
235
                    # no record with 'special_sauce'
236
                    return ( [ { authid => $expected_authid } ], 1 );
237
                } elsif (
238
                    $search_query->{query}->{bool}->{must}[1]->{term}->{'subject-heading-thesaurus.ci_raw'} eq 'z' )
239
                {
240
                    # for 'notdefined' we return the only record with 008/11 = 'z'
241
                    return ( [], 0 );
242
                } else {
243
244
                    # other cases - nothing
245
                    return ( [], 0 );
246
                }
247
            } elsif ( scalar @{ $search_query->{query}->{bool}->{must} } == 1 ) {
248
                return ['no thesaurus checking at all'];
249
            }
250
        }
251
    );
217
252
218
    $search_query = undef;
253
    # Special case continued: but it should not match an authority record with a different thesaurus
219
    ($search_query) = $heading->_search('match-heading');
254
    # defined in 040 $f
220
    $terms          = $search_query->{query}->{bool}->{must};
255
    $field   = MARC::Field->new( '650', ' ', '7', a => 'Uncles', x => 'Fiction', 2 => 'special_sauce_2' );
221
    $expected_terms = [
256
    $heading = C4::Heading->new_from_field($field);
222
        { term => { 'match-heading.ci_raw' => 'Uncles generalsubdiv Fiction' } },
257
223
    ];
258
    ($matched_auths) = $heading->_search('match-heading');
259
    $expected_result = [];
224
    is_deeply(
260
    is_deeply(
225
        $terms, $expected_terms,
261
        $matched_auths, $expected_result,
226
        "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurusDisabled"
262
        'When thesaurus in subfield 2, and nothing is found, we search again for notdefined (008_11 = z), and get no results because 040 $f with different value exists in the auth rec.'
227
    );
263
    );
228
264
265
    # When LinkerConsiderThesaurus off, no attantion is being paid on the thesaurus
266
    t::lib::Mocks::mock_preference( 'LinkerConsiderThesaurus', '0' );
267
268
    ($matched_auths) = $heading->_search('match-heading');
269
    $expected_result = ['no thesaurus checking at all'];
270
    is_deeply(
271
        $matched_auths, $expected_result,
272
        "When thesaurus in subfield 2, and nothing is found, we don't search again if LinkerConsiderThesaurus disabled"
273
    );
229
};
274
};
230
275
231
subtest "authorities exact match tests" => sub {
276
subtest "authorities exact match tests" => sub {
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t (-3 / +54 lines)
Lines 967-973 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () t Link Here
967
967
968
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authority tests' => sub {
968
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authority tests' => sub {
969
969
970
    plan tests => 5;
970
    plan tests => 9;
971
971
972
    t::lib::Mocks::mock_preference( 'marcflavour',             'MARC21' );
972
    t::lib::Mocks::mock_preference( 'marcflavour',             'MARC21' );
973
    t::lib::Mocks::mock_preference( 'ElasticsearchMARCFormat', 'base64ISO2709' );
973
    t::lib::Mocks::mock_preference( 'ElasticsearchMARCFormat', 'base64ISO2709' );
Lines 996-1001 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori Link Here
996
            sort        => 0,
996
            sort        => 0,
997
            marc_type   => 'marc21',
997
            marc_type   => 'marc21',
998
            marc_field  => '185v',
998
            marc_field  => '185v',
999
        },
1000
        {
1001
            name        => 'subject-heading-thesaurus',
1002
            type        => 'string',
1003
            facet       => 0,
1004
            suggestible => 0,
1005
            searchable  => 1,
1006
            sort        => 0,
1007
            marc_type   => 'marc21',
1008
            marc_field  => '008_/11',
1009
        },
1010
        {
1011
            name        => 'subject-heading-thesaurus',
1012
            type        => 'string',
1013
            facet       => 0,
1014
            suggestible => 0,
1015
            searchable  => 1,
1016
            sort        => 0,
1017
            marc_type   => 'marc21',
1018
            marc_field  => '040f',
999
        }
1019
        }
1000
    );
1020
    );
1001
1021
Lines 1041-1047 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori Link Here
1041
    $marc_record_3->append_fields(
1061
    $marc_record_3->append_fields(
1042
        MARC::Field->new( '185', '', '', v => 'Formsubdiv' ),
1062
        MARC::Field->new( '185', '', '', v => 'Formsubdiv' ),
1043
    );
1063
    );
1044
    my $records = [ $marc_record_1, $marc_record_2, $marc_record_3 ];
1064
1065
    my $marc_record_4 = MARC::Record->new();
1066
    $marc_record_4->append_fields(
1067
        MARC::Field->new( '008', ' ' x 11 . 'z' . ' ' x 28 ),
1068
        MARC::Field->new( '040', ' ', ' ', f => 'special_sauce' ),
1069
        MARC::Field->new( '150', ' ', ' ', a => 'Philosophy' ),
1070
    );
1071
1072
    my $marc_record_5 = MARC::Record->new();
1073
    $marc_record_5->append_fields(
1074
        MARC::Field->new( '008', ' ' x 11 . 'z' . ' ' x 28 ),
1075
        MARC::Field->new( '150', ' ', ' ', a => 'Philosophy' ),
1076
    );
1077
    my $records = [ $marc_record_1, $marc_record_2, $marc_record_3, $marc_record_4, $marc_record_5 ];
1045
1078
1046
    $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
1079
    $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
1047
1080
Lines 1068-1073 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori Link Here
1068
        $docs->[2]->{'match'},
1101
        $docs->[2]->{'match'},
1069
        "Third record heading should contain the subfield"
1102
        "Third record heading should contain the subfield"
1070
    );
1103
    );
1104
    is(
1105
        scalar( @{ $docs->[3]->{'subject-heading-thesaurus'} } ),
1106
        1,
1107
        "Only one subject-heading-thesaurus element for a record with 040 \$f"
1108
    );
1109
    is_deeply(
1110
        $docs->[3]->{'subject-heading-thesaurus'}->[0],
1111
        'special_sauce',
1112
        "Fourth record's subject-heading-thesaurus taken from 040 \$f"
1113
    );
1114
    is(
1115
        scalar( @{ $docs->[4]->{'subject-heading-thesaurus'} } ),
1116
        1,
1117
        "Just one subject-heading-thesaurus element for a record with 008/11 = 'z' and without 040 \$f"
1118
    );
1119
    is_deeply(
1120
        $docs->[4]->{'subject-heading-thesaurus'}->[0],
1121
        'z', "Fifth record's subject-heading-thesaurus taken from 008/11"
1122
    );
1071
1123
1072
};
1124
};
1073
1125
1074
- 

Return to bug 39503