@@ -, +, @@ stored as array --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 18 +++++++++++------- catalogue/search.pl | 4 ++-- .../prog/en/modules/catalogue/advsearch.tt | 5 +++++ 3 files changed, 18 insertions(+), 9 deletions(-) --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -85,15 +85,21 @@ sub build_query { $query = '*' unless defined $query; my $res; + my $fields = $self->_search_fields({ + is_opac => $options{is_opac}, + weighted_fields => $options{weighted_fields}, + }); + if ($options{whole_record}) { + push @$fields, 'marc_data_array.*'; + } $res->{query} = { query_string => { query => $query, fuzziness => $fuzzy_enabled ? 'auto' : '0', default_operator => 'AND', - fields => $self->_search_fields({ is_opac => $options{is_opac}, weighted_fields => $options{weighted_fields} }), + fields => $fields, lenient => JSON::true, analyze_wildcard => JSON::true, - fields => $options{fields} || [], } }; @@ -182,7 +188,7 @@ sub build_browse_query { $stopwords_removed, $query_type ) = $builder->build_query_compat( \@operators, \@operands, \@indexes, - \@limits, \@sort_by, $scan, $lang ); + \@limits, \@sort_by, $scan, $lang, $params ); This handles a search using the same api as L does. @@ -204,7 +210,6 @@ sub build_query_compat { my @index_params = $self->_convert_index_fields(@$indexes); my $limits = $self->_fix_limit_special_cases($orig_limits); if ( $params->{suppress} ) { push @$limits, "suppress:0"; } - # Merge the indexes in with the search terms and the operands so that # each search thing is a handy unit. unshift @$operators, undef; # The first one can't have an op @@ -237,6 +242,7 @@ sub build_query_compat { $options{sort} = \@sort_params; $options{is_opac} = $params->{is_opac}; $options{weighted_fields} = $params->{weighted_fields}; + $options{whole_record} = $params->{whole_record}; my $query = $self->build_query( $query_str, %options ); # We roughly emulate the CGI parameters of the zebra query builder @@ -1040,15 +1046,14 @@ sub _search_fields { $params //= { is_opac => 0, weighted_fields => 0, + whole_record => 0, # This is a hack for authorities build_authorities_query # can hopefully be removed in the future subfield => undef, }; - my $cache = Koha::Caches->get_instance(); my $cache_key = 'elasticsearch_search_fields' . ($params->{is_opac} ? '_opac' : '_staff_client'); my $search_fields = $cache->get_from_cache($cache_key, { unsafe => 1 }); - if (!$search_fields) { # The reason we don't use Koha::SearchFields->search here is we don't # want or need resultset wrapped as Koha::SearchField object. @@ -1096,7 +1101,6 @@ sub _search_fields { } @{$search_fields} ]; } - if ($params->{weighted_fields}) { return [map { join('^', @{$_}) } @{$search_fields}]; } --- a/catalogue/search.pl +++ a/catalogue/search.pl @@ -354,7 +354,6 @@ if ( $template_type eq 'advsearch' ) { # * we can edit the values by changing the key # * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null) my $params = $cgi->Vars; - # Params that can have more than one value # sort by is used to sort the query # in theory can have more than one but generally there's just one @@ -464,6 +463,7 @@ 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; $offset = 0 if $offset < 0; my $page = $cgi->param('page') || 1; #my $offset = ($page-1)*$results_per_page; @@ -483,7 +483,7 @@ my $searcher = Koha::SearchEngine::Search->new( $query_type ) = $builder->build_query_compat( \@operators, \@operands, \@indexes, \@limits, - \@sort_by, $scan, $lang, { weighted_fields => !$cgi->param('advsearch') }); + \@sort_by, $scan, $lang, { weighted_fields => !$cgi->param('advsearch'), whole_record => $whole_record }); ## parse the query_cgi string and put it into a form suitable for s my @query_inputs; --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -1,4 +1,5 @@ [% USE raw %] +[% USE Koha %] [% USE Asset %] [% USE Branches %] [% SET footerjs = 1 %] @@ -89,6 +90,10 @@
Search for + [% IF Koha.Preference('ElasticsearchMARCFormat') == 'ARRAY' %] + + + [% END %] [% FOREACH search_box IN search_boxes_loop %] [% IF ( search_boxes_label ) %]
[% ELSE %]
[% END %] [% IF ( expanded_options ) %] --