Bugzilla – Attachment 67470 Details for
Bug 18374
Respect QueryAutoTruncate syspref in Elasticsearch
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18374: (QA follow-up) Tidy up code
Bug-18374-QA-follow-up-Tidy-up-code.patch (text/plain), 4.76 KB, created by
Julian Maurice
on 2017-09-29 14:21:10 UTC
(
hide
)
Description:
Bug 18374: (QA follow-up) Tidy up code
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2017-09-29 14:21:10 UTC
Size:
4.76 KB
patch
obsolete
>From 066a9d86620e68f45a59c36b3770435bb512db92 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Fri, 29 Sep 2017 16:12:23 +0200 >Subject: [PATCH] Bug 18374: (QA follow-up) Tidy up code > >Signed-off-by: Julian Maurice <julian.maurice@biblibre.com> >--- > Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 16 ++++----- > .../Koha_SearchEngine_Elasticsearch_Search.t | 38 +++++++++++++++++----- > 2 files changed, 37 insertions(+), 17 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 9e8210982c..5635c85064 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -715,14 +715,14 @@ to ensure those parts are correct. > sub _clean_search_term { > my ( $self, $term ) = @_; > >- my $auto_truncation = C4::Context->preference("QueryAutoTruncate") || 0; >+ my $auto_truncation = C4::Context->preference("QueryAutoTruncate") || 0; > > # Some hardcoded searches (like with authorities) produce things like > # 'an=123', when it ought to be 'an:123' for our purposes. > $term =~ s/=/:/g; > $term = $self->_convert_index_strings_freeform($term); > $term =~ s/[{}]/"/g; >- $term = $self->_truncate_terms($term) if ( $auto_truncation ); >+ $term = $self->_truncate_terms($term) if ($auto_truncation); > return $term; > } > >@@ -793,16 +793,16 @@ operands. > =cut > > sub _truncate_terms { >- my ($self, $query) = @_; >+ my ( $self, $query ) = @_; > my @stops = qw/and or not/; > my @new_terms; >- my @split_query = split /[\(\s\)]/, $query ; >- foreach my $term ( @split_query ) { >- next if ($term eq '' || $term eq ' ' ) ; >- $term .= "*" unless ( ( grep { lc($term) =~ /^$_$/ } @stops ) || ($term =~ /\*$/ ) ); >+ my @split_query = split /[\(\s\)]/, $query; >+ foreach my $term (@split_query) { >+ next if ( $term eq '' || $term eq ' ' ); >+ $term .= "*" unless ( ( grep { lc($term) =~ /^$_$/ } @stops ) || ( $term =~ /\*$/ ) ); > push @new_terms, $term; > } >- $query=join ' ' ,@new_terms; >+ $query = join ' ', @new_terms; > return $query; > } > >diff --git a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t >index 8afa74bc1a..f547fcbc17 100644 >--- a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t >+++ b/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t >@@ -102,18 +102,38 @@ subtest 'build_query tests' => sub { > ok( !defined $query->{aggregations}{holdingbranch}, > 'holdingbranch not added to facets if DisplayLibraryFacets=home' ); > >- t::lib::Mocks::mock_preference('QueryAutoTruncate',''); >- ( undef, $query ) = $builder->build_query_compat( undef, ['donald duck'] ); >- is( $query->{query}{query_string}{query}, "(donald duck)", "query not altered if QueryAutoTruncate disabled" ); >+ t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '' ); > >- t::lib::Mocks::mock_preference('QueryAutoTruncate','1'); > ( undef, $query ) = $builder->build_query_compat( undef, ['donald duck'] ); >- is( $query->{query}{query_string}{query}, "(donald* duck*)", "simple query is auto truncated when QueryAutoTruncate enabled" ); >- ( undef, $query ) = $builder->build_query_compat( undef, ['donald or duck and mickey not mouse'] ); >- is( $query->{query}{query_string}{query}, "(donald* or duck* and mickey* not mouse*)", "reserved words are not affected by QueryAutoTruncate" ); #Ensure reserved words are not truncated >- ( undef, $query ) = $builder->build_query_compat( undef, ['donald* duck*'] ); >- is( $query->{query}{query_string}{query}, "(donald* duck*)", "query with '*' is unaltered when QueryAutoTruncate is enabled" ); >+ is( >+ $query->{query}{query_string}{query}, >+ "(donald duck)", >+ "query not altered if QueryAutoTruncate disabled" >+ ); > >+ t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' ); > >+ ( undef, $query ) = $builder->build_query_compat( undef, ['donald duck'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ "(donald* duck*)", >+ "simple query is auto truncated when QueryAutoTruncate enabled" >+ ); >+ >+ # Ensure reserved words are not truncated >+ ( undef, $query ) = $builder->build_query_compat( undef, >+ ['donald or duck and mickey not mouse'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ "(donald* or duck* and mickey* not mouse*)", >+ "reserved words are not affected by QueryAutoTruncate" >+ ); >+ >+ ( undef, $query ) = $builder->build_query_compat( undef, ['donald* duck*'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ "(donald* duck*)", >+ "query with '*' is unaltered when QueryAutoTruncate is enabled" >+ ); > }; > >-- >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 18374
:
61806
|
61952
|
61953
|
61954
|
61955
|
61983
|
64903
|
64904
|
67098
|
67099
|
67100
|
67467
|
67468
|
67469
|
67470
|
67727
|
68062
|
68063
|
68064
|
68065
|
68066
|
68067
|
68068