Lines 24-30
use Module::Load::Conditional qw/check_install/;
Link Here
|
24 |
|
24 |
|
25 |
BEGIN { |
25 |
BEGIN { |
26 |
if ( check_install( module => 'Test::DBIx::Class' ) ) { |
26 |
if ( check_install( module => 'Test::DBIx::Class' ) ) { |
27 |
plan tests => 3; |
27 |
plan tests => 6; |
28 |
} else { |
28 |
} else { |
29 |
plan skip_all => "Need Test::DBIx::Class" |
29 |
plan skip_all => "Need Test::DBIx::Class" |
30 |
} |
30 |
} |
Lines 36-41
use Test::DBIx::Class;
Link Here
|
36 |
use_ok('C4::Search'); |
36 |
use_ok('C4::Search'); |
37 |
can_ok('C4::Search', |
37 |
can_ok('C4::Search', |
38 |
qw/_build_initial_query/); |
38 |
qw/_build_initial_query/); |
|
|
39 |
can_ok('C4::Search', |
40 |
qw/buildQuery/); |
41 |
use_ok("Net::Z3950::ZOOM"); |
42 |
|
43 |
subtest "buildQuery basic tests" => sub { |
44 |
plan tests => 91; |
45 |
|
46 |
my $q; |
47 |
my($ccl_errcode, $ccl_errstr, $ccl_errpos); |
48 |
#FIXME: would it be better to use our real ccl.properties file? |
49 |
my $config = q( |
50 |
kw 1=1016 |
51 |
wrdl 4=6 |
52 |
rtrn 5=1 |
53 |
right-Truncation rtrn |
54 |
rk 2=102 |
55 |
ti 1=4 |
56 |
title ti |
57 |
ext 4=1 6=3 |
58 |
Title-cover 1=36 |
59 |
r1 9=32 |
60 |
r2 9=28 |
61 |
r3 9=26 |
62 |
r4 9=24 |
63 |
r5 9=22 |
64 |
r6 9=20 |
65 |
r7 9=18 |
66 |
r8 9=16 |
67 |
r9 9=14 |
68 |
phr 4=1 |
69 |
fuzzy 5=103 |
70 |
ccode 1=8009 |
71 |
); |
72 |
my $res; |
73 |
|
74 |
my $operators = [""]; |
75 |
my $operands = [""]; |
76 |
my $indexes = [""]; |
77 |
my $limits = [""]; |
78 |
my $sort_by = [""]; |
79 |
my $scan; |
80 |
my $lang; |
81 |
my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type); |
82 |
|
83 |
t::lib::Mocks::mock_preference('QueryWeightFields', '1'); |
84 |
t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); |
85 |
t::lib::Mocks::mock_preference('UseQueryParser', '0'); |
86 |
$operands->[0] = "test"; |
87 |
($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = |
88 |
C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); |
89 |
is($error,undef,"Error is correct"); |
90 |
is($query,'(rk=(kw,wrdl,rtrn=test )) ','Query is correct with auto truncation'); |
91 |
is($simple_query,'test',"Simple query is correct"); |
92 |
is($query_cgi,'idx=kw&q=test','Query cgi is correct'); |
93 |
is($query_desc,'kw,wrdl: test','Query desc is correct'); |
94 |
is($limit,undef,"Limit is correct"); |
95 |
is($limit_cgi,undef,"Limit cgi is correct"); |
96 |
is($limit_desc,undef,"Limit desc is correct"); |
97 |
is($query_type,undef,"Query type is correct"); |
98 |
$operands = [""]; |
99 |
$q = Net::Z3950::ZOOM::query_create(); |
100 |
($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); |
101 |
$res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, |
102 |
$ccl_errcode, $ccl_errstr, $ccl_errpos |
103 |
); |
104 |
is($res,0,"created CCL2RPN query"); |
105 |
is($ccl_errcode,0); |
106 |
is($ccl_errstr,""); |
107 |
is($ccl_errpos,0); |
108 |
Net::Z3950::ZOOM::query_destroy($q); |
109 |
|
110 |
t::lib::Mocks::mock_preference('QueryWeightFields', '1'); |
111 |
t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); |
112 |
t::lib::Mocks::mock_preference('UseQueryParser', '0'); |
113 |
$operands->[0] = "test*"; |
114 |
($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = |
115 |
C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); |
116 |
is($error,undef,"Error is correct"); |
117 |
is($query,'(rk=(kw,wrdl,rtrn=test )) ','Query is correct with manual truncation'); |
118 |
is($simple_query,'test*',"Simple query is correct"); |
119 |
is($query_cgi,'idx=kw&q=test%2A','Query cgi is correct'); |
120 |
is($query_desc,'kw,wrdl: test*','Query desc is correct'); |
121 |
is($limit,undef,"Limit is correct"); |
122 |
is($limit_cgi,undef,"Limit cgi is correct"); |
123 |
is($limit_desc,undef,"Limit desc is correct"); |
124 |
is($query_type,undef,"Query type is correct"); |
125 |
$operands = [""]; |
126 |
$q = Net::Z3950::ZOOM::query_create(); |
127 |
($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); |
128 |
$res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, |
129 |
$ccl_errcode, $ccl_errstr, $ccl_errpos |
130 |
); |
131 |
is($res,0,"created CCL2RPN query"); |
132 |
is($ccl_errcode,0); |
133 |
is($ccl_errstr,""); |
134 |
is($ccl_errpos,0); |
135 |
Net::Z3950::ZOOM::query_destroy($q); |
136 |
|
137 |
t::lib::Mocks::mock_preference('QueryWeightFields', '1'); |
138 |
t::lib::Mocks::mock_preference('QueryAutoTruncate', '0'); |
139 |
t::lib::Mocks::mock_preference('UseQueryParser', '0'); |
140 |
$operands->[0] = "test"; |
141 |
($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = |
142 |
C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); |
143 |
is($error,undef,"Error is correct"); |
144 |
is($query,'(rk=(Title-cover,ext,r1="test" or ti,ext,r2="test" or Title-cover,phr,r3="test" or ti,wrdl,r4="test" or wrdl,fuzzy,r8="test" or wrdl,right-Truncation,r9="test" or wrdl,r9="test")) ','Query is correct with weighted fields'); |
145 |
is($simple_query,'test',"Simple query is correct"); |
146 |
is($query_cgi,'idx=kw&q=test','Query cgi is correct'); |
147 |
is($query_desc,'kw,wrdl: test','Query desc is correct'); |
148 |
is($limit,undef,"Limit is correct"); |
149 |
is($limit_cgi,undef,"Limit cgi is correct"); |
150 |
is($limit_desc,undef,"Limit desc is correct"); |
151 |
is($query_type,undef,"Query type is correct"); |
152 |
$operands = [""]; |
153 |
$q = Net::Z3950::ZOOM::query_create(); |
154 |
($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); |
155 |
$res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, |
156 |
$ccl_errcode, $ccl_errstr, $ccl_errpos |
157 |
); |
158 |
is($res,0,"created CCL2RPN query"); |
159 |
is($ccl_errcode,0); |
160 |
is($ccl_errstr,""); |
161 |
is($ccl_errpos,0); |
162 |
Net::Z3950::ZOOM::query_destroy($q); |
163 |
|
164 |
t::lib::Mocks::mock_preference('QueryWeightFields', '1'); |
165 |
t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); |
166 |
t::lib::Mocks::mock_preference('UseQueryParser', '0'); |
167 |
$operands->[0] = "test"; |
168 |
$limits->[0] = "ccode:REF"; |
169 |
($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = |
170 |
C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); |
171 |
is($error,undef,"Error is correct"); |
172 |
is($query,'(rk=(kw,wrdl,rtrn=test )) and ccode=REF','Query is correct with auto truncation and limits'); |
173 |
is($simple_query,'test',"Simple query is correct"); |
174 |
is($query_cgi,'idx=kw&q=test','Query cgi is correct'); |
175 |
is($query_desc,'kw,wrdl: test','Query desc is correct'); |
176 |
is($limit,'and ccode=REF',"Limit is correct"); |
177 |
is($limit_cgi,'&limit=ccode%3AREF',"Limit cgi is correct"); |
178 |
is($limit_desc,'ccode:REF',"Limit desc is correct"); |
179 |
is($query_type,undef,"Query type is correct"); |
180 |
$operands = [""]; |
181 |
$limits = [""]; |
182 |
$q = Net::Z3950::ZOOM::query_create(); |
183 |
($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); |
184 |
$res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, |
185 |
$ccl_errcode, $ccl_errstr, $ccl_errpos |
186 |
); |
187 |
is($res,0,"created CCL2RPN query"); |
188 |
is($ccl_errcode,0); |
189 |
is($ccl_errstr,""); |
190 |
is($ccl_errpos,0); |
191 |
Net::Z3950::ZOOM::query_destroy($q); |
192 |
|
193 |
t::lib::Mocks::mock_preference('QueryWeightFields', '1'); |
194 |
t::lib::Mocks::mock_preference('QueryAutoTruncate', '0'); |
195 |
t::lib::Mocks::mock_preference('UseQueryParser', '0'); |
196 |
$operands->[0] = "test"; |
197 |
$limits->[0] = "ccode:REF"; |
198 |
($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = |
199 |
C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); |
200 |
is($error,undef,"Error is correct"); |
201 |
is($query,'(rk=(Title-cover,ext,r1="test" or ti,ext,r2="test" or Title-cover,phr,r3="test" or ti,wrdl,r4="test" or wrdl,fuzzy,r8="test" or wrdl,right-Truncation,r9="test" or wrdl,r9="test")) and ccode=REF','Query is correct with weighted fields and limits'); |
202 |
is($simple_query,'test',"Simple query is correct"); |
203 |
is($query_cgi,'idx=kw&q=test','Query cgi is correct'); |
204 |
is($query_desc,'kw,wrdl: test','Query desc is correct'); |
205 |
is($limit,'and ccode=REF',"Limit is correct"); |
206 |
is($limit_cgi,'&limit=ccode%3AREF',"Limit cgi is correct"); |
207 |
is($limit_desc,'ccode:REF',"Limit desc is correct"); |
208 |
is($query_type,undef,"Query type is correct"); |
209 |
$operands = [""]; |
210 |
$limits = [""]; |
211 |
$q = Net::Z3950::ZOOM::query_create(); |
212 |
($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); |
213 |
$res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, |
214 |
$ccl_errcode, $ccl_errstr, $ccl_errpos |
215 |
); |
216 |
is($res,0,"created CCL2RPN query"); |
217 |
is($ccl_errcode,0); |
218 |
is($ccl_errstr,""); |
219 |
is($ccl_errpos,0); |
220 |
Net::Z3950::ZOOM::query_destroy($q); |
221 |
|
222 |
t::lib::Mocks::mock_preference('QueryWeightFields', '1'); |
223 |
t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); |
224 |
t::lib::Mocks::mock_preference('UseQueryParser', '0'); |
225 |
$operators->[0] = "and"; |
226 |
$operands->[0] = "one"; |
227 |
$operands->[1] = "two"; |
228 |
$indexes->[0] = "kw"; |
229 |
$indexes->[1] = "title"; |
230 |
$limits->[0] = "ccode:REF"; |
231 |
($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = |
232 |
C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); |
233 |
is($error,undef,"Error is correct"); |
234 |
is($query,'(rk=(kw,wrdl,rtrn=one )) and (rk=(title,wrdl,rtrn=two )) and ccode=REF','Query is correct with auto truncation, limits, and using indexes and operators'); |
235 |
is($simple_query,'one',"Simple query is correct?"); |
236 |
is($query_cgi,'idx=kw&q=one&op=%20and%20&idx=title&q=two','Query cgi is correct'); |
237 |
is($query_desc,'kw,wrdl: one and title,wrdl: two','Query desc is correct'); |
238 |
is($limit,'and ccode=REF',"Limit is correct"); |
239 |
is($limit_cgi,'&limit=ccode%3AREF',"Limit cgi is correct"); |
240 |
is($limit_desc,'ccode:REF',"Limit desc is correct"); |
241 |
is($query_type,undef,"Query type is correct"); |
242 |
$operators = [""]; |
243 |
$operands = [""]; |
244 |
$indexes = [""]; |
245 |
$limits = [""]; |
246 |
$q = Net::Z3950::ZOOM::query_create(); |
247 |
($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); |
248 |
$res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, |
249 |
$ccl_errcode, $ccl_errstr, $ccl_errpos |
250 |
); |
251 |
is($res,0,"created CCL2RPN query"); |
252 |
is($ccl_errcode,0); |
253 |
is($ccl_errstr,""); |
254 |
is($ccl_errpos,0); |
255 |
Net::Z3950::ZOOM::query_destroy($q); |
256 |
|
257 |
t::lib::Mocks::mock_preference('QueryWeightFields', '1'); |
258 |
t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); |
259 |
t::lib::Mocks::mock_preference('UseQueryParser', '0'); |
260 |
$operands->[0] = "one and two"; |
261 |
($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = |
262 |
C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); |
263 |
is($error,undef,"Error is correct"); |
264 |
is($query,'(rk=(kw,wrdl,rtrn=one and two )) ','Query is correct with auto truncation and unstructured query'); |
265 |
is($simple_query,'one and two',"Simple query is correct"); |
266 |
is($query_cgi,'idx=kw&q=one%20and%20two','Query cgi is correct'); |
267 |
is($query_desc,'kw,wrdl: one and two','Query desc is correct'); |
268 |
is($limit,undef,"Limit is correct"); |
269 |
is($limit_cgi,undef,"Limit cgi is correct"); |
270 |
is($limit_desc,undef,"Limit desc is correct"); |
271 |
is($query_type,undef,"Query type is correct"); |
272 |
$operands = [""]; |
273 |
$q = Net::Z3950::ZOOM::query_create(); |
274 |
($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); |
275 |
$res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, |
276 |
$ccl_errcode, $ccl_errstr, $ccl_errpos |
277 |
); |
278 |
is($res,0,"created CCL2RPN query"); |
279 |
is($ccl_errcode,0); |
280 |
is($ccl_errstr,""); |
281 |
is($ccl_errpos,0); |
282 |
Net::Z3950::ZOOM::query_destroy($q); |
283 |
}; |
39 |
|
284 |
|
40 |
subtest "_build_initial_query tests" => sub { |
285 |
subtest "_build_initial_query tests" => sub { |
41 |
|
286 |
|
42 |
- |
|
|