From 71d638acd017cab4eaac0095961fd0be41686e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Tue, 7 Oct 2025 11:45:02 -0300 Subject: [PATCH] Bug 40966: Regression tests Tests verify that whole_record and weighted_fields parameters are correctly included in the query_cgi string returned by build_query_compat(), ensuring these parameters are preserved in facet links and pagination. To test: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t => FAIL: The values are not being passed around Signed-off-by: David Nind --- .../SearchEngine/Elasticsearch/QueryBuilder.t | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index a47dd32a3d..7d51c2a9a6 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -252,7 +252,7 @@ subtest 'build_authorities_query_compat() tests' => sub { }; subtest 'build_query tests' => sub { - plan tests => 69; + plan tests => 72; my $qb; @@ -342,6 +342,31 @@ subtest 'build_query tests' => sub { is( $query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query' ); is( $query_desc, '(title:("donald duck")) (author:(walt disney))', 'query desc ok for multiterm query' ); + # Test whole_record and weighted_fields parameters in query_cgi + ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( + undef, ['test'], ['kw'], undef, undef, undef, undef, + { whole_record => 1, weighted_fields => 1, weight_search_submitted => 1 } + ); + is( + $query_cgi, 'idx=kw&q=test&weight_search=1&weight_search_submitted=1&whole_record=1', + 'query_cgi includes whole_record, weight_search and weight_search_submitted parameters' + ); + + ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( + undef, ['test'], ['kw'], undef, undef, undef, undef, + { whole_record => 1 } + ); + is( $query_cgi, 'idx=kw&q=test&whole_record=1', 'query_cgi includes whole_record parameter only' ); + + ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( + undef, ['test'], ['kw'], undef, undef, undef, undef, + { weighted_fields => 1, weight_search_submitted => 1 } + ); + is( + $query_cgi, 'idx=kw&q=test&weight_search=1&weight_search_submitted=1', + 'query_cgi includes weight_search and weight_search_submitted parameters only' + ); + ( undef, $query ) = $qb->build_query_compat( undef, ['2019'], ['yr,st-year'] ); is( $query->{query}{bool}{must}[0]{query_string}{query}, -- 2.39.5