From 7829f7b3031550140325940ac1877bd225ada604 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 3 Oct 2025 19:35:43 +0000 Subject: [PATCH] Bug 40853: Unit tests Signed-off-by: Jason Robb --- .../SearchEngine/Elasticsearch/QueryBuilder.t | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index a47dd32a3d4..485e59fd26f 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -1205,8 +1205,9 @@ subtest "_sort_field() tests" => sub { }; subtest "_build_field_match_boost_query() tests" => sub { - plan tests => 10; + plan tests => 11; + t::lib::Mocks::mock_preference( 'ElasticsearchBoostFieldMatchAmount', '0' ); my $qb; ok( @@ -1269,6 +1270,18 @@ subtest "_build_field_match_boost_query() tests" => sub { 'Title is not converted to title-cover' ); + t::lib::Mocks::mock_preference( 'ElasticsearchBoostFieldMatchAmount', '10' ); + $field_match_boost_query = $qb->_build_field_match_boost_query( { indexes => \@indexes, operands => \@operands } ); + is_deeply( + $field_match_boost_query, + [ + { match => { 'title-cover' => { boost => 10, query => 'turkey' } } }, + { match => { 'subject' => { boost => 10, query => 'gravy' } } }, + { match => { 'title-cover' => { boost => 10, query => 'mashed' } } }, + ], + 'Boost is added to fields as expected only when pref has a value' + ); + t::lib::Mocks::mock_preference( 'ElasticsearchBoostFieldMatch', '0' ); t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' ); my ( undef, $query ) = $qb->build_query_compat( ['AND'], [ 'donald duck', 'disney' ], [ 'title', 'author' ] ); @@ -1283,7 +1296,8 @@ subtest "_build_field_match_boost_query() tests" => sub { 'No should query added for boosting' ); - t::lib::Mocks::mock_preference( 'ElasticsearchBoostFieldMatch', '1' ); + t::lib::Mocks::mock_preference( 'ElasticsearchBoostFieldMatch', '1' ); + t::lib::Mocks::mock_preference( 'ElasticsearchBoostFieldMatchAmount', '0' ); ( undef, $query ) = $qb->build_query_compat( ['AND'], [ 'donald duck', 'disney' ], [ 'title', 'author' ] ); is_deeply( $query->{query}{bool}{should}, -- 2.39.5