Bugzilla – Attachment 99158 Details for
Bug 12430
Relevance ranking should also be used without QueryWeightFields system preference
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Unit tests for buildQuery
Unit-tests-for-buildQuery.patch (text/plain), 12.01 KB, created by
David Cook
on 2020-02-18 08:34:38 UTC
(
hide
)
Description:
Unit tests for buildQuery
Filename:
MIME Type:
Creator:
David Cook
Created:
2020-02-18 08:34:38 UTC
Size:
12.01 KB
patch
obsolete
>From 72a426b52795a48cc02d140d5eb90f06973fe722 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Tue, 18 Feb 2020 03:02:55 +0000 >Subject: [PATCH] Unit tests for buildQuery > >This patch adds unit tets for buildQuery, especially focusing on >the use of the (rk=()) wrapper. > >Note that the Net::Z3950::ZOOM library is used to test the queries >for CCL validity on top of the string matching used in the >got/expected comparisons. > >https://bugs.koha-community.org/show_bug.cgi?id=12430 >--- > t/Search.t | 247 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 246 insertions(+), 1 deletion(-) > >diff --git a/t/Search.t b/t/Search.t >index 0959c85de0..6dff31e36e 100755 >--- a/t/Search.t >+++ b/t/Search.t >@@ -24,7 +24,7 @@ use Module::Load::Conditional qw/check_install/; > > BEGIN { > if ( check_install( module => 'Test::DBIx::Class' ) ) { >- plan tests => 3; >+ plan tests => 6; > } else { > plan skip_all => "Need Test::DBIx::Class" > } >@@ -36,6 +36,251 @@ use Test::DBIx::Class; > use_ok('C4::Search'); > can_ok('C4::Search', > qw/_build_initial_query/); >+can_ok('C4::Search', >+ qw/buildQuery/); >+use_ok("Net::Z3950::ZOOM"); >+ >+subtest "buildQuery basic tests" => sub { >+ plan tests => 91; >+ >+ my $q; >+ my($ccl_errcode, $ccl_errstr, $ccl_errpos); >+ #FIXME: would it be better to use our real ccl.properties file? >+ my $config = q( >+ kw 1=1016 >+ wrdl 4=6 >+ rtrn 5=1 >+ right-Truncation rtrn >+ rk 2=102 >+ ti 1=4 >+ title ti >+ ext 4=1 6=3 >+ Title-cover 1=36 >+ r1 9=32 >+ r2 9=28 >+ r3 9=26 >+ r4 9=24 >+ r5 9=22 >+ r6 9=20 >+ r7 9=18 >+ r8 9=16 >+ r9 9=14 >+ phr 4=1 >+ fuzzy 5=103 >+ ccode 1=8009 >+ ); >+ my $res; >+ >+ my $operators = [""]; >+ my $operands = [""]; >+ my $indexes = [""]; >+ my $limits = [""]; >+ my $sort_by = [""]; >+ my $scan; >+ my $lang; >+ my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type); >+ >+ t::lib::Mocks::mock_preference('QueryWeightFields', '1'); >+ t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); >+ t::lib::Mocks::mock_preference('UseQueryParser', '0'); >+ $operands->[0] = "test"; >+ ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = >+ C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); >+ is($error,undef,"Error is correct"); >+ is($query,'(rk=(kw,wrdl,rtrn=test )) ','Query is correct with auto truncation'); >+ is($simple_query,'test',"Simple query is correct"); >+ is($query_cgi,'idx=kw&q=test','Query cgi is correct'); >+ is($query_desc,'kw,wrdl: test','Query desc is correct'); >+ is($limit,undef,"Limit is correct"); >+ is($limit_cgi,undef,"Limit cgi is correct"); >+ is($limit_desc,undef,"Limit desc is correct"); >+ is($query_type,undef,"Query type is correct"); >+ $operands = [""]; >+ $q = Net::Z3950::ZOOM::query_create(); >+ ($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); >+ $res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, >+ $ccl_errcode, $ccl_errstr, $ccl_errpos >+ ); >+ is($res,0,"created CCL2RPN query"); >+ is($ccl_errcode,0); >+ is($ccl_errstr,""); >+ is($ccl_errpos,0); >+ Net::Z3950::ZOOM::query_destroy($q); >+ >+ t::lib::Mocks::mock_preference('QueryWeightFields', '1'); >+ t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); >+ t::lib::Mocks::mock_preference('UseQueryParser', '0'); >+ $operands->[0] = "test*"; >+ ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = >+ C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); >+ is($error,undef,"Error is correct"); >+ is($query,'(rk=(kw,wrdl,rtrn=test )) ','Query is correct with manual truncation'); >+ is($simple_query,'test*',"Simple query is correct"); >+ is($query_cgi,'idx=kw&q=test%2A','Query cgi is correct'); >+ is($query_desc,'kw,wrdl: test*','Query desc is correct'); >+ is($limit,undef,"Limit is correct"); >+ is($limit_cgi,undef,"Limit cgi is correct"); >+ is($limit_desc,undef,"Limit desc is correct"); >+ is($query_type,undef,"Query type is correct"); >+ $operands = [""]; >+ $q = Net::Z3950::ZOOM::query_create(); >+ ($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); >+ $res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, >+ $ccl_errcode, $ccl_errstr, $ccl_errpos >+ ); >+ is($res,0,"created CCL2RPN query"); >+ is($ccl_errcode,0); >+ is($ccl_errstr,""); >+ is($ccl_errpos,0); >+ Net::Z3950::ZOOM::query_destroy($q); >+ >+ t::lib::Mocks::mock_preference('QueryWeightFields', '1'); >+ t::lib::Mocks::mock_preference('QueryAutoTruncate', '0'); >+ t::lib::Mocks::mock_preference('UseQueryParser', '0'); >+ $operands->[0] = "test"; >+ ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = >+ C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); >+ is($error,undef,"Error is correct"); >+ 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'); >+ is($simple_query,'test',"Simple query is correct"); >+ is($query_cgi,'idx=kw&q=test','Query cgi is correct'); >+ is($query_desc,'kw,wrdl: test','Query desc is correct'); >+ is($limit,undef,"Limit is correct"); >+ is($limit_cgi,undef,"Limit cgi is correct"); >+ is($limit_desc,undef,"Limit desc is correct"); >+ is($query_type,undef,"Query type is correct"); >+ $operands = [""]; >+ $q = Net::Z3950::ZOOM::query_create(); >+ ($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); >+ $res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, >+ $ccl_errcode, $ccl_errstr, $ccl_errpos >+ ); >+ is($res,0,"created CCL2RPN query"); >+ is($ccl_errcode,0); >+ is($ccl_errstr,""); >+ is($ccl_errpos,0); >+ Net::Z3950::ZOOM::query_destroy($q); >+ >+ t::lib::Mocks::mock_preference('QueryWeightFields', '1'); >+ t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); >+ t::lib::Mocks::mock_preference('UseQueryParser', '0'); >+ $operands->[0] = "test"; >+ $limits->[0] = "ccode:REF"; >+ ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = >+ C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); >+ is($error,undef,"Error is correct"); >+ is($query,'(rk=(kw,wrdl,rtrn=test )) and ccode=REF','Query is correct with auto truncation and limits'); >+ is($simple_query,'test',"Simple query is correct"); >+ is($query_cgi,'idx=kw&q=test','Query cgi is correct'); >+ is($query_desc,'kw,wrdl: test','Query desc is correct'); >+ is($limit,'and ccode=REF',"Limit is correct"); >+ is($limit_cgi,'&limit=ccode%3AREF',"Limit cgi is correct"); >+ is($limit_desc,'ccode:REF',"Limit desc is correct"); >+ is($query_type,undef,"Query type is correct"); >+ $operands = [""]; >+ $limits = [""]; >+ $q = Net::Z3950::ZOOM::query_create(); >+ ($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); >+ $res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, >+ $ccl_errcode, $ccl_errstr, $ccl_errpos >+ ); >+ is($res,0,"created CCL2RPN query"); >+ is($ccl_errcode,0); >+ is($ccl_errstr,""); >+ is($ccl_errpos,0); >+ Net::Z3950::ZOOM::query_destroy($q); >+ >+ t::lib::Mocks::mock_preference('QueryWeightFields', '1'); >+ t::lib::Mocks::mock_preference('QueryAutoTruncate', '0'); >+ t::lib::Mocks::mock_preference('UseQueryParser', '0'); >+ $operands->[0] = "test"; >+ $limits->[0] = "ccode:REF"; >+ ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = >+ C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); >+ is($error,undef,"Error is correct"); >+ 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'); >+ is($simple_query,'test',"Simple query is correct"); >+ is($query_cgi,'idx=kw&q=test','Query cgi is correct'); >+ is($query_desc,'kw,wrdl: test','Query desc is correct'); >+ is($limit,'and ccode=REF',"Limit is correct"); >+ is($limit_cgi,'&limit=ccode%3AREF',"Limit cgi is correct"); >+ is($limit_desc,'ccode:REF',"Limit desc is correct"); >+ is($query_type,undef,"Query type is correct"); >+ $operands = [""]; >+ $limits = [""]; >+ $q = Net::Z3950::ZOOM::query_create(); >+ ($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); >+ $res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, >+ $ccl_errcode, $ccl_errstr, $ccl_errpos >+ ); >+ is($res,0,"created CCL2RPN query"); >+ is($ccl_errcode,0); >+ is($ccl_errstr,""); >+ is($ccl_errpos,0); >+ Net::Z3950::ZOOM::query_destroy($q); >+ >+ t::lib::Mocks::mock_preference('QueryWeightFields', '1'); >+ t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); >+ t::lib::Mocks::mock_preference('UseQueryParser', '0'); >+ $operators->[0] = "and"; >+ $operands->[0] = "one"; >+ $operands->[1] = "two"; >+ $indexes->[0] = "kw"; >+ $indexes->[1] = "title"; >+ $limits->[0] = "ccode:REF"; >+ ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = >+ C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); >+ is($error,undef,"Error is correct"); >+ 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'); >+ is($simple_query,'one',"Simple query is correct?"); >+ is($query_cgi,'idx=kw&q=one&op=%20and%20&idx=title&q=two','Query cgi is correct'); >+ is($query_desc,'kw,wrdl: one and title,wrdl: two','Query desc is correct'); >+ is($limit,'and ccode=REF',"Limit is correct"); >+ is($limit_cgi,'&limit=ccode%3AREF',"Limit cgi is correct"); >+ is($limit_desc,'ccode:REF',"Limit desc is correct"); >+ is($query_type,undef,"Query type is correct"); >+ $operators = [""]; >+ $operands = [""]; >+ $indexes = [""]; >+ $limits = [""]; >+ $q = Net::Z3950::ZOOM::query_create(); >+ ($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); >+ $res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, >+ $ccl_errcode, $ccl_errstr, $ccl_errpos >+ ); >+ is($res,0,"created CCL2RPN query"); >+ is($ccl_errcode,0); >+ is($ccl_errstr,""); >+ is($ccl_errpos,0); >+ Net::Z3950::ZOOM::query_destroy($q); >+ >+ t::lib::Mocks::mock_preference('QueryWeightFields', '1'); >+ t::lib::Mocks::mock_preference('QueryAutoTruncate', '1'); >+ t::lib::Mocks::mock_preference('UseQueryParser', '0'); >+ $operands->[0] = "one and two"; >+ ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) = >+ C4::Search::buildQuery($operators,$operands,$indexes,$limits,$sort_by,$scan,$lang); >+ is($error,undef,"Error is correct"); >+ is($query,'(rk=(kw,wrdl,rtrn=one and two )) ','Query is correct with auto truncation and unstructured query'); >+ is($simple_query,'one and two',"Simple query is correct"); >+ is($query_cgi,'idx=kw&q=one%20and%20two','Query cgi is correct'); >+ is($query_desc,'kw,wrdl: one and two','Query desc is correct'); >+ is($limit,undef,"Limit is correct"); >+ is($limit_cgi,undef,"Limit cgi is correct"); >+ is($limit_desc,undef,"Limit desc is correct"); >+ is($query_type,undef,"Query type is correct"); >+ $operands = [""]; >+ $q = Net::Z3950::ZOOM::query_create(); >+ ($ccl_errcode, $ccl_errstr, $ccl_errpos) = (0,"",0); >+ $res = Net::Z3950::ZOOM::query_ccl2rpn($q, $query, $config, >+ $ccl_errcode, $ccl_errstr, $ccl_errpos >+ ); >+ is($res,0,"created CCL2RPN query"); >+ is($ccl_errcode,0); >+ is($ccl_errstr,""); >+ is($ccl_errpos,0); >+ Net::Z3950::ZOOM::query_destroy($q); >+}; > > subtest "_build_initial_query tests" => sub { > >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 12430
:
28880
|
96167
|
98188
|
98619
|
99141
|
99142
|
99158
|
114129
|
114130
|
114131
|
114132
|
114137
|
114138
|
114200
|
114205
|
114275