|
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 { |
| 232 |
- |
|
|