From ae96f50ad8b23b2f8afbc3011db545b1624ed487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cohen=20Arazi?= Date: Tue, 7 Oct 2025 11:36:53 -0300 Subject: [PATCH] Bug 40966: Make sure 'whole_record' and 'weighted_fields' are passed around The ES query builder correctly handles this parameters (passed from search.pl and opac-search.pl) when it builds the ES query. But the returned 'query_cgi' that is used later for keeping the search results query context for building things like facets, just doesn't pass this values around, leading to a loss of them on the generated links. This patch makes sure they are passed around. To test: 1. Apply the regression tests 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t => FAIL: Tests fail! These params are not passed around! 3. Set ElasticsearchMARCFormat="Searchable array" 4. Reindex all the things: k$ koha-elasticsearch --rebuild -d -v kohadev 5. Go to advanced search, using the 'More options' option. 6. Check 'Search entire MARC record' and 'Apply weights to search' 7. Perform a search on 'FULL TEXT' => SUCCESS: The URL contains `whole_record=on` and `weighted_fields=on` 8. Hover on any facet and look at the link => FAIL: It doesn't contain them! 9. Apply this patch 10. Restart all k$ restart_all 11. Refresh the search results 12. Repeat 6 => SUCCESS: Links have the needed parameters! 13. Repeat 2 => SUCCESS: Tests pass! the parameters are passed around! 14. Sign off :-D --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 8ee830c6498..42eed857f8f 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -352,7 +352,9 @@ sub build_query_compat { $query_cgi .= 'idx=' . uri_escape_utf8( $index // '' ) . '&q=' . uri_escape_utf8($oand); $query_cgi .= '&op=' . uri_escape_utf8($otor) if $otor; } - $query_cgi .= '&scan=1' if ($scan); + $query_cgi .= '&scan=1' if ($scan); + $query_cgi .= '&weighted_fields=1' if ( $params->{weighted_fields} ); + $query_cgi .= '&whole_record=1' if ( $params->{whole_record} ); my $simple_query; $simple_query = $operands->[0] if @$operands == 1; -- 2.51.0