View | Details | Raw Unified | Return to bug 40966
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-1 / +4 lines)
Lines 352-358 sub build_query_compat { Link Here
352
        $query_cgi .= 'idx=' . uri_escape_utf8( $index // '' ) . '&q=' . uri_escape_utf8($oand);
352
        $query_cgi .= 'idx=' . uri_escape_utf8( $index // '' ) . '&q=' . uri_escape_utf8($oand);
353
        $query_cgi .= '&op=' . uri_escape_utf8($otor) if $otor;
353
        $query_cgi .= '&op=' . uri_escape_utf8($otor) if $otor;
354
    }
354
    }
355
    $query_cgi .= '&scan=1' if ($scan);
355
    $query_cgi .= '&scan=1'                    if ($scan);
356
    $query_cgi .= '&weight_search=1'           if ( $params->{weighted_fields} );
357
    $query_cgi .= '&weight_search_submitted=1' if ( $params->{weight_search_submitted} );
358
    $query_cgi .= '&whole_record=1'            if ( $params->{whole_record} );
356
359
357
    my $simple_query;
360
    my $simple_query;
358
    $simple_query = $operands->[0] if @$operands == 1;
361
    $simple_query = $operands->[0] if @$operands == 1;
(-)a/catalogue/search.pl (-8 / +31 lines)
Lines 277-282 if ( $template_type eq 'advsearch' ) { Link Here
277
        @operands  = $cgi->multi_param('q');
277
        @operands  = $cgi->multi_param('q');
278
        @operators = @sanitized_operators;
278
        @operators = @sanitized_operators;
279
        @indexes   = $cgi->multi_param('idx');
279
        @indexes   = $cgi->multi_param('idx');
280
        $expanded  = 1;                          # Force expanded options when editing search
280
        $template->param(
281
        $template->param(
281
            sort => scalar $cgi->param('sort_by'),
282
            sort => scalar $cgi->param('sort_by'),
282
        );
283
        );
Lines 341-347 if ( $template_type eq 'advsearch' ) { Link Here
341
    {
342
    {
342
        $expanded = C4::Context->preference("expandedSearchOption") || 0
343
        $expanded = C4::Context->preference("expandedSearchOption") || 0
343
            if !defined($expanded) || $expanded !~ /^0|1$/;
344
            if !defined($expanded) || $expanded !~ /^0|1$/;
344
        $template->param( expanded_options => $expanded );
345
346
        # Force expanded options if weight_search_submitted or whole_record are present
347
        $expanded = 1 if $cgi->param('weight_search_submitted') || $cgi->param('whole_record');
348
349
        $template->param(
350
            expanded_options        => $expanded,
351
            weight_search_submitted => scalar $cgi->param('weight_search_submitted'),
352
            whole_record            => scalar $cgi->param('whole_record'),
353
        );
345
    }
354
    }
346
355
347
    $template->param( virtualshelves => C4::Context->preference("virtualshelves") );
356
    $template->param( virtualshelves => C4::Context->preference("virtualshelves") );
Lines 436-446 for ( my $ii = 0 ; $ii < @operands ; ++$ii ) { Link Here
436
445
437
# Params that can only have one value
446
# Params that can only have one value
438
my $scan             = $params->{'scan'};
447
my $scan             = $params->{'scan'};
439
my $count            = C4::Context->preference('numSearchResults')         || 20;
448
my $count            = C4::Context->preference('numSearchResults') || 20;
440
my $results_per_page = $params->{'count'}                                  || $count;
449
my $results_per_page = $params->{'count'}                          || $count;
441
my $offset           = $params->{'offset'}                                 || 0;
450
my $offset           = $params->{'offset'}                         || 0;
442
my $whole_record     = $params->{'whole_record'}                           || 0;
451
my $whole_record     = $params->{'whole_record'}                   || 0;
443
my $weight_search    = $params->{'advsearch'} ? $params->{'weight_search'} || 0 : 1;
452
my $weight_search    = $params->{'weight_search_submitted'}
453
    ? ( $params->{'weight_search'} ? 1 : 0 )    # Form was submitted, use actual checkbox value
454
    : 1;                                        # Form not submitted
444
$offset = 0 if $offset < 0;
455
$offset = 0 if $offset < 0;
445
456
446
# Define some global variables
457
# Define some global variables
Lines 462-468 for ( my $i = 0 ; $i < @operands ; $i++ ) { Link Here
462
    )
473
    )
463
    = $builder->build_query_compat(
474
    = $builder->build_query_compat(
464
    \@operators, \@operands, \@indexes, \@limits,
475
    \@operators, \@operands, \@indexes, \@limits,
465
    \@sort_by,   $scan,      $lang, { weighted_fields => $weight_search, whole_record => $whole_record }
476
    \@sort_by,
477
    $scan, $lang,
478
    {
479
        weighted_fields         => $weight_search,
480
        whole_record            => $whole_record,
481
        weight_search_submitted => $params->{'weight_search_submitted'}
482
    }
466
    );
483
    );
467
484
468
$template->param( search_query => $query ) if C4::Context->preference('DumpSearchQueryTemplate');
485
$template->param( search_query => $query ) if C4::Context->preference('DumpSearchQueryTemplate');
Lines 559-565 if ( $hits == 0 && $basic_search ) { Link Here
559
        )
576
        )
560
        = $builder->build_query_compat(
577
        = $builder->build_query_compat(
561
        \@operators, \@operands, \@indexes, \@limits,
578
        \@operators, \@operands, \@indexes, \@limits,
562
        \@sort_by,   $scan,      $lang, { weighted_fields => $weight_search, whole_record => $whole_record }
579
        \@sort_by,
580
        $scan, $lang,
581
        {
582
            weighted_fields         => $weight_search,
583
            whole_record            => $whole_record,
584
            weight_search_submitted => $params->{'weight_search_submitted'}
585
        }
563
        );
586
        );
564
    my $quoted_results_hashref;
587
    my $quoted_results_hashref;
565
    eval {
588
    eval {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt (-2 / +19 lines)
Lines 153-165 Link Here
153
                    [% IF ( expanded_options ) %]
153
                    [% IF ( expanded_options ) %]
154
                        <p>
154
                        <p>
155
                            [% IF Koha.Preference('ElasticsearchMARCFormat') == 'ARRAY' %]
155
                            [% IF Koha.Preference('ElasticsearchMARCFormat') == 'ARRAY' %]
156
                                <label><input type="checkbox" name="whole_record" /> Search entire MARC record</label>
156
                                <label>
157
                                    [% IF whole_record %]
158
                                        <input type="checkbox" name="whole_record" checked="checked" />
159
                                    [% ELSE %]
160
                                        <input type="checkbox" name="whole_record" />
161
                                    [% END %]
162
                                    Search entire MARC record</label
163
                                >
157
                            [% END %]
164
                            [% END %]
158
                            <span id="weight_search">
165
                            <span id="weight_search">
159
                                <label><input type="checkbox" name="weight_search" checked="checked" /> Apply field weights to search</label>
166
                                <input type="hidden" name="weight_search_submitted" value="1" />
167
                                <label>
168
                                    [% IF weight_search_submitted && !weight_search %]
169
                                        <input type="checkbox" name="weight_search" />
170
                                    [% ELSE %]
171
                                        [%# enabled by default or when weight_search==true %]
172
                                        <input type="checkbox" name="weight_search" checked="checked" />
173
                                    [% END %]
174
                                    Apply field weights to search</label
175
                                >
160
                            </span>
176
                            </span>
161
                        </p>
177
                        </p>
162
                    [% ELSE %]
178
                    [% ELSE %]
179
                        <input type="hidden" name="weight_search_submitted" value="1" />
163
                        <input type="hidden" name="weight_search" value="1" />
180
                        <input type="hidden" name="weight_search" value="1" />
164
                    [% END %]
181
                    [% END %]
165
                [% END %]
182
                [% END %]
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-advsearch.tt (-1 / +8 lines)
Lines 151-163 Link Here
151
                                [% IF ( expanded_options ) %]
151
                                [% IF ( expanded_options ) %]
152
                                    [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %]
152
                                    [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %]
153
                                        <div id="weight_search">
153
                                        <div id="weight_search">
154
                                            <input type="hidden" name="weight_search_submitted" value="1" />
154
                                            <label>
155
                                            <label>
155
                                                <input type="checkbox" name="weight_search" checked="checked" />
156
                                                [% IF weight_search_submitted && !weight_search %]
157
                                                    <input type="checkbox" name="weight_search" />
158
                                                [% ELSE %]
159
                                                    [%# enabled by default or when weight_search==true %]
160
                                                    <input type="checkbox" name="weight_search" checked="checked" />
161
                                                [% END %]
156
                                                Apply field weights to search
162
                                                Apply field weights to search
157
                                            </label>
163
                                            </label>
158
                                        </div>
164
                                        </div>
159
                                    [% END %]
165
                                    [% END %]
160
                                [% ELSE %]
166
                                [% ELSE %]
167
                                    <input type="hidden" name="weight_search_submitted" value="1" />
161
                                    <input type="hidden" name="weight_search" value="1" />
168
                                    <input type="hidden" name="weight_search" value="1" />
162
                                [% END %]
169
                                [% END %]
163
                                [% IF Koha.Preference('IncludeSeeFromInSearches') %]
170
                                [% IF Koha.Preference('IncludeSeeFromInSearches') %]
(-)a/opac/opac-search.pl (-9 / +23 lines)
Lines 216-222 if ( $cgi->cookie("search_path_code") ) { Link Here
216
    if ( $pathcode eq 'ads' ) {
216
    if ( $pathcode eq 'ads' ) {
217
        $template->param( 'ReturnPath' => '/cgi-bin/koha/opac-search.pl?returntosearch=1' );
217
        $template->param( 'ReturnPath' => '/cgi-bin/koha/opac-search.pl?returntosearch=1' );
218
    } elsif ( $pathcode eq 'exs' ) {
218
    } elsif ( $pathcode eq 'exs' ) {
219
        $template->param( 'ReturnPath' => '/cgi-bin/koha/opac-search.pl?expanded_options=1&returntosearch=1' );
219
        my $return_params = 'expanded_options=1&returntosearch=1';
220
        $return_params .= '&weight_search_submitted=1' if $cgi->param('weight_search_submitted');
221
        $return_params .= '&weight_search=1'           if $cgi->param('weight_search');
222
        $template->param( 'ReturnPath' => "/cgi-bin/koha/opac-search.pl?$return_params" );
220
    } else {
223
    } else {
221
        warn "ReturnPath switch error";
224
        warn "ReturnPath switch error";
222
    }
225
    }
Lines 357-362 if ( $template_type && $template_type eq 'advsearch' ) { Link Here
357
        }
360
        }
358
    }
361
    }
359
362
363
    # Force expanded options if weight_search_submitted is present
364
    if ( $cgi->param('weight_search_submitted') ) {
365
        $template->param( expanded_options => 1 );
366
    }
367
368
    # Always pass weight_search_submitted to template for checkbox logic
369
    $template->param( weight_search_submitted => scalar $cgi->param('weight_search_submitted') );
370
360
    output_html_with_http_headers $cgi, $cookie, $template->output;
371
    output_html_with_http_headers $cgi, $cookie, $template->output;
361
    exit;
372
    exit;
362
}
373
}
Lines 494-500 $offset = 0 if $offset < 0; Link Here
494
my $page = $cgi->param('page') || 1;
505
my $page = $cgi->param('page') || 1;
495
$offset = ( $page - 1 ) * $results_per_page if $page > 1;
506
$offset = ( $page - 1 ) * $results_per_page if $page > 1;
496
my $hits;
507
my $hits;
497
my $weight_search = $cgi->param('advsearch') ? $cgi->param('weight_search') || 0 : 1;
508
my $weight_search = $cgi->param('weight_search_submitted')
509
    ? ( $cgi->param('weight_search') ? 1 : 0 )    # Form was submitted, use actual checkbox value
510
    : 1;                                          # Form not submitted
498
511
499
# Define some global variables
512
# Define some global variables
500
my ( $error, $query, $simple_query, $query_cgi, $query_desc, $limit, $limit_cgi, $limit_desc, $query_type );
513
my ( $error, $query, $simple_query, $query_cgi, $query_desc, $limit, $limit_cgi, $limit_desc, $query_type );
Lines 523-531 if ( C4::Context->preference('OpacSuppression') ) { Link Here
523
    0,
536
    0,
524
    $lang,
537
    $lang,
525
    {
538
    {
526
        suppress        => $suppress,
539
        suppress                => $suppress,
527
        is_opac         => 1,
540
        is_opac                 => 1,
528
        weighted_fields => $weight_search
541
        weighted_fields         => $weight_search,
542
        weight_search_submitted => $cgi->param('weight_search_submitted')
529
    }
543
    }
530
    );
544
    );
531
545
Lines 644-652 for ( my $i = 0 ; $i < @servers ; $i++ ) { Link Here
644
                0,
658
                0,
645
                $lang,
659
                $lang,
646
                {
660
                {
647
                    suppress        => $suppress,
661
                    suppress                => $suppress,
648
                    is_opac         => 1,
662
                    is_opac                 => 1,
649
                    weighted_fields => $weight_search
663
                    weighted_fields         => $weight_search,
664
                    weight_search_submitted => $cgi->param('weight_search_submitted')
650
                }
665
                }
651
                );
666
                );
652
            my $quoted_results_hashref;
667
            my $quoted_results_hashref;
653
- 

Return to bug 40966