Bugzilla – Attachment 182263 Details for
Bug 39079
Matchpoints with multiple fields require all fields to match under Elasticsearch
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39079: Follow 'and_or' variable when passed to build_auth_query_compat
Bug-39079-Follow-andor-variable-when-passed-to-bui.patch (text/plain), 5.81 KB, created by
Martin Renvoize (ashimema)
on 2025-05-12 11:42:31 UTC
(
hide
)
Description:
Bug 39079: Follow 'and_or' variable when passed to build_auth_query_compat
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-05-12 11:42:31 UTC
Size:
5.81 KB
patch
obsolete
>From b7d85739ae6e532cb6625c221dc31024800f68c2 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 10 Feb 2025 17:31:06 +0000 >Subject: [PATCH] Bug 39079: Follow 'and_or' variable when passed to > build_auth_query_compat > >When building queries for matchign Zebra uses OR to combine searches - Elasticsearch >has been effectively using 'AND' - this patch checks whether and_or has been passed >and follows the variable when present. > >To test: >1 - Have an import file of auths with multiple 035 >2 - Setup an authority matching rule > Search index: other-control-number > Score: 1000 > Tag: 035 > Subfields: a >3 - Make sure Koha is using Elasticsearch >4 - Stage file without matching, import file >5 - Stage file again, using your matching rule >6 - Note all records match >7 - Setup Cataloging->Marc modification template >8 - Add an action to delete first 035 field >9 - Run it against the records you just imported > You can use a report: > SELECT authid FROM auth_header WHERE authid > #### (find the lowest new record number in batch you imported) >10 - Change matching rule in batch to none, then back to your rule >11 - No matches! >12 - Apply patch, restart all >13 - Set matchign rule to none, then back to your rule >14 - Matches! > >Signed-off-by: Magnus Enger <magnus@libriotech.no> >Works as advertised! >Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> >--- > .../Elasticsearch/QueryBuilder.pm | 12 ++++++-- > .../SearchEngine/Elasticsearch/QueryBuilder.t | 30 +++++++++++++++++-- > 2 files changed, 36 insertions(+), 6 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 253df42d692..431f9f2e114 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -511,9 +511,13 @@ sub build_authorities_query { > # Merge the query parts appropriately > # 'should' behaves like 'or' > # 'must' behaves like 'and' >- # Zebra behaviour seem to match must so using that here >+ # We will obey the first and_or passed in here: >+ # authfinder.pl is hardcoded to 'AND' >+ # authorities-home.pl only allows searching a single index >+ # for matching we 'OR' together multiple fields >+ my $search_type = defined $search->{and_or} && uc( $search->{and_or}->[0] ) eq 'OR' ? 'should' : 'must'; > my $elastic_query = {}; >- $elastic_query->{bool}->{must} = \@query_parts; >+ $elastic_query->{bool}->{$search_type} = \@query_parts; > > # Filter by authtypecode if set > if ( $search->{authtypecode} ) { >@@ -549,7 +553,8 @@ thesaurus. If left blank, any field is used. > > =item and_or > >-Totally ignored. It is never used in L<C4::AuthoritiesMarc::SearchAuthorities>. >+This takes an array to match Zebra, however, we only care about the first value. >+This will determine whether searches are combined as 'must' (AND) or 'should' (OR). > > =item excluding > >@@ -663,6 +668,7 @@ sub build_authorities_query_compat { > my %search = ( > searches => \@searches, > authtypecode => $authtypecode, >+ and_or => $and_or, > ); > $search{sort} = \%sort if %sort; > my $query = $self->build_authorities_query( \%search ); >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index f92d78083f8..a8310a74117 100755 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -85,7 +85,7 @@ $se->mock( > > subtest 'build_authorities_query_compat() tests' => sub { > >- plan tests => 72; >+ plan tests => 81; > > my $qb; > >@@ -94,8 +94,32 @@ subtest 'build_authorities_query_compat() tests' => sub { > 'Creating new query builder object for authorities' > ); > >+ my $koha_name = 'any'; >+ my $search_term = 'a'; >+ my $query = $qb->build_authorities_query_compat( >+ [$koha_name], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', >+ 'asc' >+ ); >+ ok( !defined $query->{query}->{bool}->{should}, "Should query not used if 'and_or' not passed" ); >+ ok( defined $query->{query}->{bool}->{must}, "Must query used if 'and_or' not passed" ); >+ is( $query->{query}->{bool}->{must}[0]->{query_string}->{query}, "a*" ); >+ $query = $qb->build_authorities_query_compat( >+ [$koha_name], ['and'], undef, ['contains'], [$search_term], 'AUTH_TYPE', >+ 'asc' >+ ); >+ ok( !defined $query->{query}->{bool}->{should}, "Should query not used when 'and_or' passed 'and'" ); >+ ok( defined $query->{query}->{bool}->{must}, "Must query used when 'and_or' passed 'and'" ); >+ is( $query->{query}->{bool}->{must}[0]->{query_string}->{query}, "a*" ); >+ $query = $qb->build_authorities_query_compat( >+ [$koha_name], ['or'], undef, ['contains'], [$search_term], 'AUTH_TYPE', >+ 'asc' >+ ); >+ ok( defined $query->{query}->{bool}->{should}, "Should query used if 'and_or' passed 'or'" ); >+ ok( defined $query->{query}->{bool}->{should}, "Must query not used if 'and_or' passed 'or'" ); >+ is( $query->{query}->{bool}->{should}[0]->{query_string}->{query}, "a*" ); >+ > my $koha_to_index_name = $Koha::SearchEngine::Elasticsearch::QueryBuilder::koha_to_index_name; >- my $search_term = 'a'; >+ $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', >@@ -175,7 +199,7 @@ subtest 'build_authorities_query_compat() tests' => sub { > } > > # Sorting >- my $query = $qb->build_authorities_query_compat( >+ $query = $qb->build_authorities_query_compat( > ['mainentry'], undef, undef, ['start'], [$search_term], 'AUTH_TYPE', > 'HeadingAsc' > ); >-- >2.49.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 39079
:
177706
|
180108
|
180151
| 182263