From 84218b0e2be26cc4b1ba5985e27034d52c3ad0aa Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Tue, 28 Jun 2022 10:04:08 -1000 Subject: [PATCH] Bug 31061: OPACSuppress behavior with Elasticsearch OPACSuppress is system preference to hide records in OPAC search by adding a limit in search query. With Zebra, this limit is : not Suppress=1 https://git.koha-community.org/Koha-community/Koha/src/commit/244b847a08bf61a747a1e4be4eed86cc776eabd6/Koha/SearchEngine/Zebra/QueryBuilder.pm#L83 With Elasticsearch this limit is currently quite different : suppress:false https://git.koha-community.org/Koha-community/Koha/src/commit/244b847a08bf61a747a1e4be4eed86cc776eabd6/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm#L286 We whould like to have several MARC fields with 'suppress' search field. To distinguish several causes of hidden at OPAC. Any of those fields having 1 must hide at OPAC. Syntax 'NOT(suppress:true)' does that, like with Zebra. Test plan : 1) Use search engine Elasticsearch 2) Disable system preference OpacSuppression 3) Search in OPAC for all records : '*:*' => Note how many results 4) Enable system preference OpacSuppression 5) Edit a biblio record with 942$n set to YES 6) Search in OPAC for all records : '*:*' => Note how many results, you should have 1 less than 3) 7) Edit a biblio record with 942$n set to NO 8) Search in OPAC for all records : '*:*' => Note how many results, you should have same number as 3) 9) Edit a biblio record to remove 942$n 10) Search in OPAC for all records : '*:*' => Note how many results, you should have same number as 3) --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 2 +- .../Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 7250ea6048..624fce53f8 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -283,7 +283,7 @@ sub build_query_compat { my @sort_params = $self->_convert_sort_fields(@$sort_by); my @index_params = $self->_convert_index_fields(@$indexes); $limits = $self->_fix_limit_special_cases($orig_limits); - if ( $params->{suppress} ) { push @$limits, "suppress:false"; } + if ( $params->{suppress} ) { push @$limits, "NOT(suppress:true)"; } # Merge the indexes in with the search terms and the operands so that # each search thing is a handy unit. unshift @$operators, undef; # The first one can't have an op diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index 4e8964e682..9e971a57a6 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -460,15 +460,15 @@ subtest 'build_query tests' => sub { ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 1 } ); is( $query->{query}{query_string}{query}, - '(title:"donald duck") AND suppress:false', - "query of specific field is added AND suppress:false" + '(title:"donald duck") AND NOT(suppress:true)', + "suppress part of the query added correctly" ); ( undef, $query, $simple_query, $query_cgi, $query_desc ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } ); is( $query->{query}{query_string}{query}, '(title:"donald duck")', - "query of specific field is not added AND suppress:0" + "suppress part of the query not added" ); ( undef, $query ) = $qb->build_query_compat( ['AND'], ['title:"donald duck"'], undef, ['author:Dillinger Escaplan'] ); -- 2.35.3