Bugzilla – Attachment 77089 Details for
Bug 19604
Elasticsearch Fixes for build_authorities_query for auth searching
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 19604: Unit tests
Bug-19604-Unit-tests.patch (text/plain), 5.33 KB, created by
Katrin Fischer
on 2018-07-18 18:18:11 UTC
(
hide
)
Description:
Bug 19604: Unit tests
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2018-07-18 18:18:11 UTC
Size:
5.33 KB
patch
obsolete
>From 9f634ba7a96ba7ff254933d866bf7634b03a59e3 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 17 Nov 2017 14:07:41 +0000 >Subject: [PATCH] Bug 19604: Unit tests > >1 - Apply previous patches >2 - prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >3 - Should be green >4 - high fives! > >Signed-off-by: Nicolas Legrand <nicolas.legrand@bulac.fr> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > .../SearchEngine/Elasticsearch/QueryBuilder.t | 56 ++++++++++++++++--- > 1 file changed, 47 insertions(+), 9 deletions(-) > >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index 025c78842f..0a8f4cf57d 100644 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -24,6 +24,7 @@ use Koha::Database; > use Koha::SearchEngine::Elasticsearch::QueryBuilder > > subtest 'build_authorities_query_compat() tests' => sub { >+ plan tests => 37; > > my $qb; > >@@ -34,15 +35,52 @@ subtest 'build_authorities_query_compat() tests' => sub { > > my $koha_to_index_name = $Koha::SearchEngine::Elasticsearch::QueryBuilder::koha_to_index_name; > my $search_term = 'a'; >+ foreach my $koha_name ( keys %{ $koha_to_index_name } ) { >+ my $query = $qb->build_authorities_query_compat( [ $koha_name ], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' ); >+ if ( $koha_name eq 'all' ) { >+ is( $query->{query}->{bool}->{must}[0]->{wildcard}->{"_all.phrase"}, >+ "*a*"); >+ } else { >+ is( $query->{query}->{bool}->{must}[0]->{wildcard}->{$koha_to_index_name->{$koha_name}.".phrase"}, >+ "*a*"); >+ } >+ } > >+ $search_term = 'Donald Duck'; > foreach my $koha_name ( keys %{ $koha_to_index_name } ) { > my $query = $qb->build_authorities_query_compat( [ $koha_name ], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' ); > if ( $koha_name eq 'all' ) { >- is( $query->{query}->{bool}->{should}[0]->{match}->{_all}, >- $search_term); >+ is( $query->{query}->{bool}->{must}[0]->{wildcard}->{"_all.phrase"}, >+ "*donald*"); >+ is( $query->{query}->{bool}->{must}[1]->{wildcard}->{"_all.phrase"}, >+ "*duck*"); >+ } else { >+ is( $query->{query}->{bool}->{must}[0]->{wildcard}->{$koha_to_index_name->{$koha_name}.".phrase"}, >+ "*donald*"); >+ is( $query->{query}->{bool}->{must}[1]->{wildcard}->{$koha_to_index_name->{$koha_name}.".phrase"}, >+ "*duck*"); >+ } >+ } >+ >+ foreach my $koha_name ( keys %{ $koha_to_index_name } ) { >+ my $query = $qb->build_authorities_query_compat( [ $koha_name ], undef, undef, ['is'], [$search_term], 'AUTH_TYPE', 'asc' ); >+ if ( $koha_name eq 'all' ) { >+ is( $query->{query}->{bool}->{must}[0]->{term}->{"_all.phrase"}, >+ "donald duck"); >+ } else { >+ is( $query->{query}->{bool}->{must}[0]->{term}->{$koha_to_index_name->{$koha_name}.".phrase"}, >+ "donald duck"); >+ } >+ } >+ >+ foreach my $koha_name ( keys %{ $koha_to_index_name } ) { >+ my $query = $qb->build_authorities_query_compat( [ $koha_name ], undef, undef, ['start'], [$search_term], 'AUTH_TYPE', 'asc' ); >+ if ( $koha_name eq 'all' ) { >+ is( $query->{query}->{bool}->{must}[0]->{prefix}->{"_all.lc_raw"}, >+ "donald duck"); > } else { >- is( $query->{query}->{bool}->{should}[0]->{match}->{$koha_to_index_name->{$koha_name}}, >- $search_term); >+ is( $query->{query}->{bool}->{must}[0]->{prefix}->{$koha_to_index_name->{$koha_name}.".lc_raw"}, >+ "donald duck"); > } > } > >@@ -65,15 +103,15 @@ subtest 'build query from form subtests' => sub { > > my $query = $builder->build_authorities_query_compat( \@marclist, undef, > undef, \@operator , \@values, 'AUTH_TYPE', 'asc' ); >- is($query->{query}->{bool}->{should}[0]->{match}->{'Heading'}, "Hamilton","Expected search is populated"); >- is( scalar @{ $query->{query}->{bool}->{should} }, 1,"Only defined search is populated"); >+ is($query->{query}->{bool}->{must}[0]->{wildcard}->{'Heading.phrase'}, "*hamilton*","Expected search is populated"); >+ is( scalar @{ $query->{query}->{bool}->{must} }, 1,"Only defined search is populated"); > > @values[2] = 'Jefferson'; > $query = $builder->build_authorities_query_compat( \@marclist, undef, > undef, \@operator , \@values, 'AUTH_TYPE', 'asc' ); >- is($query->{query}->{bool}->{should}[0]->{match}->{'Heading'}, "Hamilton","First index searched as expected"); >- is($query->{query}->{bool}->{should}[1]->{match}->{'Match'}, "Jefferson","Second index searched when populated"); >- is( scalar @{ $query->{query}->{bool}->{should} }, 2,"Only defined searches are populated"); >+ is($query->{query}->{bool}->{must}[0]->{wildcard}->{'Heading.phrase'}, "*hamilton*","First index searched as expected"); >+ is($query->{query}->{bool}->{must}[1]->{wildcard}->{'Match.phrase'}, "*jefferson*","Second index searched when populated"); >+ is( scalar @{ $query->{query}->{bool}->{must} }, 2,"Only defined searches are populated"); > > > }; >-- >2.17.1
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 19604
:
69072
|
69198
|
69199
|
72807
|
72808
|
76977
|
76978
|
77088
| 77089 |
77328