diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 8ee830c649..ad339ae7e4 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -352,7 +352,10 @@ 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 .= '&weight_search=1' if ( $params->{weighted_fields} ); + $query_cgi .= '&weight_search_submitted=1' if ( $params->{weight_search_submitted} ); + $query_cgi .= '&whole_record=1' if ( $params->{whole_record} ); my $simple_query; $simple_query = $operands->[0] if @$operands == 1; diff --git a/catalogue/search.pl b/catalogue/search.pl index 762d952ae7..957a9f9dcf 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -277,6 +277,7 @@ if ( $template_type eq 'advsearch' ) { @operands = $cgi->multi_param('q'); @operators = @sanitized_operators; @indexes = $cgi->multi_param('idx'); + $expanded = 1; # Force expanded options when editing search $template->param( sort => scalar $cgi->param('sort_by'), ); @@ -341,7 +342,15 @@ if ( $template_type eq 'advsearch' ) { { $expanded = C4::Context->preference("expandedSearchOption") || 0 if !defined($expanded) || $expanded !~ /^0|1$/; - $template->param( expanded_options => $expanded ); + + # Force expanded options if weight_search_submitted or whole_record are present + $expanded = 1 if $cgi->param('weight_search_submitted') || $cgi->param('whole_record'); + + $template->param( + expanded_options => $expanded, + weight_search_submitted => scalar $cgi->param('weight_search_submitted'), + whole_record => scalar $cgi->param('whole_record'), + ); } $template->param( virtualshelves => C4::Context->preference("virtualshelves") ); @@ -436,11 +445,13 @@ for ( my $ii = 0 ; $ii < @operands ; ++$ii ) { # Params that can only have one value my $scan = $params->{'scan'}; -my $count = C4::Context->preference('numSearchResults') || 20; -my $results_per_page = $params->{'count'} || $count; -my $offset = $params->{'offset'} || 0; -my $whole_record = $params->{'whole_record'} || 0; -my $weight_search = $params->{'advsearch'} ? $params->{'weight_search'} || 0 : 1; +my $count = C4::Context->preference('numSearchResults') || 20; +my $results_per_page = $params->{'count'} || $count; +my $offset = $params->{'offset'} || 0; +my $whole_record = $params->{'whole_record'} || 0; +my $weight_search = $params->{'weight_search_submitted'} + ? ( $params->{'weight_search'} ? 1 : 0 ) # Form was submitted, use actual checkbox value + : 1; # Form not submitted $offset = 0 if $offset < 0; # Define some global variables @@ -462,7 +473,13 @@ for ( my $i = 0 ; $i < @operands ; $i++ ) { ) = $builder->build_query_compat( \@operators, \@operands, \@indexes, \@limits, - \@sort_by, $scan, $lang, { weighted_fields => $weight_search, whole_record => $whole_record } + \@sort_by, + $scan, $lang, + { + weighted_fields => $weight_search, + whole_record => $whole_record, + weight_search_submitted => $params->{'weight_search_submitted'} + } ); $template->param( search_query => $query ) if C4::Context->preference('DumpSearchQueryTemplate'); @@ -559,7 +576,13 @@ if ( $hits == 0 && $basic_search ) { ) = $builder->build_query_compat( \@operators, \@operands, \@indexes, \@limits, - \@sort_by, $scan, $lang, { weighted_fields => $weight_search, whole_record => $whole_record } + \@sort_by, + $scan, $lang, + { + weighted_fields => $weight_search, + whole_record => $whole_record, + weight_search_submitted => $params->{'weight_search_submitted'} + } ); my $quoted_results_hashref; eval { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt index ab6b53aac6..736eef6f95 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -153,13 +153,30 @@ [% IF ( expanded_options ) %]
[% IF Koha.Preference('ElasticsearchMARCFormat') == 'ARRAY' %] - + [% END %] - + +
[% ELSE %] + [% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt index 80433b2b26..39e0ce8004 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt @@ -151,13 +151,20 @@ [% IF ( expanded_options ) %] [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %]