@@ -, +, @@ --- .../Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 39 +++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -21,7 +21,7 @@ use C4::Context; use Test::Exception; use t::lib::Mocks; use t::lib::TestBuilder; -use Test::More tests => 6; +use Test::More tests => 7; use Koha::Database; use Koha::SearchEngine::Elasticsearch::QueryBuilder; @@ -485,4 +485,41 @@ subtest "_sort_field() tests" => sub { ); }; +subtest 'build_query_compat() limit tests' => sub { + plan tests => 6; + + my $builder = Koha::SearchEngine::Elasticsearch::QueryBuilder->new({ 'index' => 'biblios' }), + my @operators = (); + my @operands = (); + my @indexes = (); + my @orig_limits = ('itype:BK'); + my @sort_by = (); + my $scan = undef; + my $lang = undef; + my @params = ( \@operators, \@operands, \@indexes, \@orig_limits, \@sort_by, $scan, $lang ); + my (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ( 'itype:BK' ), "We pass through a known type"); + + @orig_limits = ('itype:BK2'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('itype:BK2' ), "We pass through and quote a known type requested as phrase"); + + @orig_limits = ('ti:monkey'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('title:monkey' ), "We convert and pass through a known type"); + + @orig_limits = ('ti,phr:monkey'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('title:"monkey"' ), "We convert, quote, and pass through a known type requested as phrase"); + + @orig_limits = ('monkey:banana'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('monkey:banana' ), "We pass through an unknown type"); + + @orig_limits = ('ti,phr:monkey'); + (undef, $query, undef, undef, undef, $limit) = $builder->build_query_compat( @params ); + is( $limit, ('title:"monkey"' ), "We quote and pass through an unknown type requested as phrase"); + +}; + $schema->storage->txn_rollback; --