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