From 37ec1af786af4ef0fbad676a72413c8a82668e10 Mon Sep 17 00:00:00 2001 From: Lari Taskula Date: Fri, 18 Oct 2024 20:32:35 +0000 Subject: [PATCH] Bug 15728: Elasticsearch - Support component records limit To test: Apply all patches from this Bug. Execute steps 5-15 both in staff client and OPAC 1. prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t 2. Set system preferences SearchEngine = Elasticsearch ShowComponentRecordsFacet = both staff interface and OPAC 3. Create a new record (leader/7 should NOT be "a" nor "b") 4. Create two new component records (leader/7 should be "a" or "b") 5. Search catalog with * 6. Observe facets containing category "Component records" 7. Note down total number of search results (referred as ALL) 8. From facets, click "Limit to component records" 9. Note down total number of component record results (referred as COMP) 10. From search results, observe your newly created component records 11. From facets under Component records, click "Show all records" 12. Observe number of search results equal to ALL 13. From facets, click "Exclude component records" 14. Observe total number of search results being ALL-COMP 15. Observe your newly created component records not part of results --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 5 +++++ .../SearchEngine/Elasticsearch/QueryBuilder.t | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index b641e97404..b680bccce8 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1150,6 +1150,11 @@ sub _fix_limit_special_cases { elsif ( $l =~ /^available$/ ) { push @new_lim, 'available:true'; } + elsif ( $l =~ /^component_records$/ ) { + push @new_lim, '(bib-level:a OR bib-level:b)'; + } elsif ( $l =~ /^exclude_component_records$/ ) { + push @new_lim, 'NOT (bib-level:a OR bib-level:b)'; + } elsif ( $l =~ /^\s*(kw\b[\w,-]*?):(.*)/) { my ( $field, $term ) = ($1, $2); if ( defined($field) && defined($term) && $field =~ /,phr$/) { diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index 4b3c4f0b2f..66adf7b99d 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 => 58; + plan tests => 60; my $qb; @@ -379,6 +379,19 @@ subtest 'build_query tests' => sub { "query with quotes is unaltered when QueryAutoTruncate is enabled" ); + ( undef, $query ) = $qb->build_query_compat( undef, ['"donald duck"'], undef, ['component_records'] ); + is( + $query->{query}{query_string}{query}, + '("donald duck") AND (bib-level:a OR bib-level:b)', + "Component records limit is handled properly" + ); + + ( undef, $query ) = $qb->build_query_compat( undef, ['"donald duck"'], undef, ['exclude_component_records'] ); + is( + $query->{query}{query_string}{query}, + '("donald duck") AND NOT (bib-level:a OR bib-level:b)', + "Host records limit is handled properly" + ); ( undef, $query ) = $qb->build_query_compat( undef, ['"donald duck" and "the mouse"'] ); is( -- 2.34.1