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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-7 / +11 lines)
Lines 85-99 sub build_query { Link Here
85
    $query = '*' unless defined $query;
85
    $query = '*' unless defined $query;
86
86
87
    my $res;
87
    my $res;
88
    my $fields = $self->_search_fields({
89
        is_opac => $options{is_opac},
90
        weighted_fields => $options{weighted_fields},
91
    });
92
    if ($options{whole_record}) {
93
        push @$fields, 'marc_data_array.*';
94
    }
88
    $res->{query} = {
95
    $res->{query} = {
89
        query_string => {
96
        query_string => {
90
            query            => $query,
97
            query            => $query,
91
            fuzziness        => $fuzzy_enabled ? 'auto' : '0',
98
            fuzziness        => $fuzzy_enabled ? 'auto' : '0',
92
            default_operator => 'AND',
99
            default_operator => 'AND',
93
            fields          => $self->_search_fields({ is_opac => $options{is_opac}, weighted_fields => $options{weighted_fields} }),
100
            fields           => $fields,
94
            lenient          => JSON::true,
101
            lenient          => JSON::true,
95
            analyze_wildcard => JSON::true,
102
            analyze_wildcard => JSON::true,
96
            fields           => $options{fields} || [],
97
        }
103
        }
98
    };
104
    };
99
105
Lines 182-188 sub build_browse_query { Link Here
182
        $stopwords_removed, $query_type
188
        $stopwords_removed, $query_type
183
      )
189
      )
184
      = $builder->build_query_compat( \@operators, \@operands, \@indexes,
190
      = $builder->build_query_compat( \@operators, \@operands, \@indexes,
185
        \@limits, \@sort_by, $scan, $lang );
191
        \@limits, \@sort_by, $scan, $lang, $params );
186
192
187
This handles a search using the same api as L<C4::Search::buildQuery> does.
193
This handles a search using the same api as L<C4::Search::buildQuery> does.
188
194
Lines 204-210 sub build_query_compat { Link Here
204
    my @index_params = $self->_convert_index_fields(@$indexes);
210
    my @index_params = $self->_convert_index_fields(@$indexes);
205
    my $limits       = $self->_fix_limit_special_cases($orig_limits);
211
    my $limits       = $self->_fix_limit_special_cases($orig_limits);
206
    if ( $params->{suppress} ) { push @$limits, "suppress:0"; }
212
    if ( $params->{suppress} ) { push @$limits, "suppress:0"; }
207
208
    # Merge the indexes in with the search terms and the operands so that
213
    # Merge the indexes in with the search terms and the operands so that
209
    # each search thing is a handy unit.
214
    # each search thing is a handy unit.
210
    unshift @$operators, undef;    # The first one can't have an op
215
    unshift @$operators, undef;    # The first one can't have an op
Lines 237-242 sub build_query_compat { Link Here
237
    $options{sort} = \@sort_params;
242
    $options{sort} = \@sort_params;
238
    $options{is_opac} = $params->{is_opac};
243
    $options{is_opac} = $params->{is_opac};
239
    $options{weighted_fields} = $params->{weighted_fields};
244
    $options{weighted_fields} = $params->{weighted_fields};
245
    $options{whole_record} = $params->{whole_record};
240
    my $query = $self->build_query( $query_str, %options );
246
    my $query = $self->build_query( $query_str, %options );
241
247
242
    # We roughly emulate the CGI parameters of the zebra query builder
248
    # We roughly emulate the CGI parameters of the zebra query builder
Lines 1040-1054 sub _search_fields { Link Here
1040
    $params //= {
1046
    $params //= {
1041
        is_opac => 0,
1047
        is_opac => 0,
1042
        weighted_fields => 0,
1048
        weighted_fields => 0,
1049
        whole_record => 0,
1043
        # This is a hack for authorities build_authorities_query
1050
        # This is a hack for authorities build_authorities_query
1044
        # can hopefully be removed in the future
1051
        # can hopefully be removed in the future
1045
        subfield => undef,
1052
        subfield => undef,
1046
    };
1053
    };
1047
1048
    my $cache = Koha::Caches->get_instance();
1054
    my $cache = Koha::Caches->get_instance();
1049
    my $cache_key = 'elasticsearch_search_fields' . ($params->{is_opac} ? '_opac' : '_staff_client');
1055
    my $cache_key = 'elasticsearch_search_fields' . ($params->{is_opac} ? '_opac' : '_staff_client');
1050
    my $search_fields = $cache->get_from_cache($cache_key, { unsafe => 1 });
1056
    my $search_fields = $cache->get_from_cache($cache_key, { unsafe => 1 });
1051
1052
    if (!$search_fields) {
1057
    if (!$search_fields) {
1053
        # The reason we don't use Koha::SearchFields->search here is we don't
1058
        # The reason we don't use Koha::SearchFields->search here is we don't
1054
        # want or need resultset wrapped as Koha::SearchField object.
1059
        # want or need resultset wrapped as Koha::SearchField object.
Lines 1096-1102 sub _search_fields { Link Here
1096
            } @{$search_fields}
1101
            } @{$search_fields}
1097
        ];
1102
        ];
1098
    }
1103
    }
1099
1100
    if ($params->{weighted_fields}) {
1104
    if ($params->{weighted_fields}) {
1101
        return [map { join('^', @{$_}) } @{$search_fields}];
1105
        return [map { join('^', @{$_}) } @{$search_fields}];
1102
    }
1106
    }
(-)a/catalogue/search.pl (-2 / +2 lines)
Lines 354-360 if ( $template_type eq 'advsearch' ) { Link Here
354
#  * we can edit the values by changing the key
354
#  * we can edit the values by changing the key
355
#  * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null)
355
#  * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null)
356
my $params = $cgi->Vars;
356
my $params = $cgi->Vars;
357
358
# Params that can have more than one value
357
# Params that can have more than one value
359
# sort by is used to sort the query
358
# sort by is used to sort the query
360
# in theory can have more than one but generally there's just one
359
# in theory can have more than one but generally there's just one
Lines 464-469 my $scan = $params->{'scan'}; Link Here
464
my $count = C4::Context->preference('numSearchResults') || 20;
463
my $count = C4::Context->preference('numSearchResults') || 20;
465
my $results_per_page = $params->{'count'} || $count;
464
my $results_per_page = $params->{'count'} || $count;
466
my $offset = $params->{'offset'} || 0;
465
my $offset = $params->{'offset'} || 0;
466
my $whole_record = $params->{'whole_record'} || 0;
467
$offset = 0 if $offset < 0;
467
$offset = 0 if $offset < 0;
468
my $page = $cgi->param('page') || 1;
468
my $page = $cgi->param('page') || 1;
469
#my $offset = ($page-1)*$results_per_page;
469
#my $offset = ($page-1)*$results_per_page;
Lines 483-489 my $searcher = Koha::SearchEngine::Search->new( Link Here
483
    $query_type
483
    $query_type
484
  )
484
  )
485
  = $builder->build_query_compat( \@operators, \@operands, \@indexes, \@limits,
485
  = $builder->build_query_compat( \@operators, \@operands, \@indexes, \@limits,
486
    \@sort_by, $scan, $lang, { weighted_fields => !$cgi->param('advsearch') });
486
    \@sort_by, $scan, $lang, { weighted_fields => !$cgi->param('advsearch'), whole_record => $whole_record });
487
487
488
## parse the query_cgi string and put it into a form suitable for <input>s
488
## parse the query_cgi string and put it into a form suitable for <input>s
489
my @query_inputs;
489
my @query_inputs;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt (-1 / +5 lines)
Lines 1-4 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Koha %]
2
[% USE Asset %]
3
[% USE Asset %]
3
[% USE Branches %]
4
[% USE Branches %]
4
[% SET footerjs = 1 %]
5
[% SET footerjs = 1 %]
Lines 89-94 Link Here
89
<!-- BOOLEAN SEARCH OPTIONS -->
90
<!-- BOOLEAN SEARCH OPTIONS -->
90
    <fieldset id="searchterms">
91
    <fieldset id="searchterms">
91
    <legend>Search for </legend>
92
    <legend>Search for </legend>
93
    [% IF Koha.Preference('ElasticsearchMARCFormat') == 'ARRAY' %]
94
        <input type="checkbox" name="whole_record">
95
        <label for="whole_record">Search entire MARC record</label>
96
    [% END %]
92
    [% FOREACH search_box IN search_boxes_loop %]
97
    [% FOREACH search_box IN search_boxes_loop %]
93
        [% IF ( search_boxes_label ) %]<div style="text-indent: 4.5em;">[% ELSE %]<div>[% END %]
98
        [% IF ( search_boxes_label ) %]<div style="text-indent: 4.5em;">[% ELSE %]<div>[% END %]
94
			[% IF ( expanded_options ) %]
99
			[% IF ( expanded_options ) %]
95
- 

Return to bug 20589