Bugzilla – Attachment 164142 Details for
Bug 32707
Elasticsearch should not auto truncate (even if QueryAutoTruncate = 1) for identifiers (and some other fields)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32707: Unit tests
Bug-32707-Unit-tests.patch (text/plain), 6.14 KB, created by
Nick Clemens (kidclamp)
on 2024-03-29 17:33:00 UTC
(
hide
)
Description:
Bug 32707: Unit tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2024-03-29 17:33:00 UTC
Size:
6.14 KB
patch
obsolete
>From eda8c672f32c02015199a5c4fbb9ce379f47d1d3 Mon Sep 17 00:00:00 2001 >From: Janusz Kaczmarek <januszop@gmail.com> >Date: Fri, 27 Oct 2023 21:06:44 +0000 >Subject: [PATCH] Bug 32707: Unit tests > >NB in t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t, >I had to modify four existing test by changing Local-number:123456 to >Personal-name:donald -- since Local-number should never be >auto truncated according to the submitted patch. > >Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net> >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> >--- > .../SearchEngine/Elasticsearch/QueryBuilder.t | 32 ++++++++++++- > .../SearchEngine/Elasticsearch/QueryBuilder.t | 45 +++++++++++++++---- > 2 files changed, 67 insertions(+), 10 deletions(-) > >diff --git a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index a507b2e0655..c2938000e41 100755 >--- a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 6; >+use Test::More tests => 7; > use t::lib::Mocks; > > use_ok('Koha::SearchEngine::Elasticsearch::QueryBuilder'); >@@ -152,6 +152,36 @@ subtest '_truncate_terms() tests' => sub { > is_deeply($res, '"donald duck"', 'quoted search terms surrounded by spaces correctly'); > }; > >+subtest '_is_safe_to_auto_truncate() tests' => sub { >+ plan tests => 7; >+ >+ my $qb; >+ ok( >+ $qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( >+ { 'index' => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX } >+ ), >+ 'Creating a new QueryBuilder object' >+ ); >+ >+ my $res = $qb->_is_safe_to_auto_truncate( undef, 'local-number:1' ); >+ is( $res, '0', 'no truncation for biblionumber - OK' ); >+ >+ $res = $qb->_is_safe_to_auto_truncate( undef, 'koha-auth-number:1' ); >+ is( $res, '0', 'no truncation for authid - OK' ); >+ >+ $res = $qb->_is_safe_to_auto_truncate( undef, 'title:some title' ); >+ is( $res, '1', 'do truncate titles - OK' ); >+ >+ $res = $qb->_is_safe_to_auto_truncate( 'local-number', undef ); >+ is( $res, '0', 'no truncation for biblionumber - OK' ); >+ >+ $res = $qb->_is_safe_to_auto_truncate( 'koha-auth-number', undef ); >+ is( $res, '0', 'no truncation for authid - OK' ); >+ >+ $res = $qb->_is_safe_to_auto_truncate( 'title', undef ); >+ is( $res, '1', 'do truncate titles - OK' ); >+}; >+ > subtest '_split_query() tests' => sub { > plan tests => 7; > >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index 277b7842809..e834187ba64 100755 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -219,7 +219,7 @@ subtest 'build_authorities_query_compat() tests' => sub { > }; > > subtest 'build_query tests' => sub { >- plan tests => 60; >+ plan tests => 63; > > my $qb; > >@@ -406,6 +406,9 @@ subtest 'build_query tests' => sub { > "all quoted strings are unaltered if more than one in query" > ); > >+ # Reset ESPreventAutoTruncate syspref >+ t::lib::Mocks::mock_preference( 'ESPreventAutoTruncate', '' ); >+ > ( undef, $query ) = $qb->build_query_compat( undef, ['barcode:123456'] ); > is( > $query->{query}{query_string}{query}, >@@ -413,34 +416,58 @@ subtest 'build_query tests' => sub { > "query of specific field is truncated" > ); > >- ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number:"123456"'] ); >+ ( undef, $query ) = $qb->build_query_compat( undef, ['Personal-name:"donald"'] ); > is( > $query->{query}{query_string}{query}, >- '(local-number:"123456")', >+ '(personal-name:"donald")', > "query of specific field including hyphen and quoted is not truncated, field name is converted to lower case" > ); > >- ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number:123456'] ); >+ ( undef, $query ) = $qb->build_query_compat( undef, ['Personal-name:donald'] ); > is( > $query->{query}{query_string}{query}, >- '(local-number:123456*)', >+ '(personal-name:donald*)', > "query of specific field including hyphen and not quoted is truncated, field name is converted to lower case" > ); > >- ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number.raw:123456'] ); >+ ( undef, $query ) = $qb->build_query_compat( undef, ['Personal-name.raw:donald'] ); > is( > $query->{query}{query_string}{query}, >- '(local-number.raw:123456*)', >+ '(personal-name.raw:donald*)', > "query of specific field including period and not quoted is truncated, field name is converted to lower case" > ); > >- ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number.raw:"123456"'] ); >+ ( undef, $query ) = $qb->build_query_compat( undef, ['Personal-name.raw:"donald"'] ); > is( > $query->{query}{query_string}{query}, >- '(local-number.raw:"123456")', >+ '(personal-name.raw:"donald")', > "query of specific field including period and quoted is not truncated, field name is converted to lower case" > ); > >+ # Set ESPreventAutoTruncate syspref >+ t::lib::Mocks::mock_preference( 'ESPreventAutoTruncate', 'barcode' ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['barcode:123456'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(barcode:123456)', >+ "query of specific field excluded by ESPreventAutoTruncate is not truncated" >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number:123456'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(local-number:123456)', >+ "query of identifier is not truncated even if QueryAutoTruncate is set" >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['onloan:true'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(onloan:true)', >+ "query of boolean type field is not truncated even if QueryAutoTruncate is set" >+ ); >+ > ( undef, $query ) = $qb->build_query_compat( undef, ['J.R.R'] ); > is( > $query->{query}{query_string}{query}, >-- >2.30.2
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 32707
:
145606
|
158007
|
158008
|
158009
|
161035
|
163748
|
163749
|
163750
|
163751
|
163759
|
163822
|
163823
|
163824
|
163880
|
163881
|
163882
|
163892
|
163893
|
163894
|
164140
|
164141
| 164142