Bugzilla – Attachment 93250 Details for
Bug 20589
Add field boosting and use elastic query fields parameter instead of deprecated _all
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20589: Add option for searching entire record if record stored as array
Bug-20589-Add-option-for-searching-entire-record-i.patch (text/plain), 5.87 KB, created by
David Gustafsson
on 2019-09-30 13:25:46 UTC
(
hide
)
Description:
Bug 20589: Add option for searching entire record if record stored as array
Filename:
MIME Type:
Creator:
David Gustafsson
Created:
2019-09-30 13:25:46 UTC
Size:
5.87 KB
patch
obsolete
>From 34ef459fdd3e3a5d71308417801a255be13ef937 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Fri, 23 Aug 2019 16:45:05 +0000 >Subject: [PATCH] Bug 20589: Add option for searching entire record if record > 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(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 53cbdc36a5..f44b422d71 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/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<C4::Search::buildQuery> 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}]; > } >diff --git a/catalogue/search.pl b/catalogue/search.pl >index 25ec0dbf08..b05e17e59e 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -346,7 +346,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 >@@ -456,6 +455,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; >@@ -475,7 +475,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 <input>s > my @query_inputs; >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 e1da7838aa..33ec5241cf 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt >+++ b/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 @@ > <!-- BOOLEAN SEARCH OPTIONS --> > <fieldset id="searchterms"> > <legend>Search for </legend> >+ [% IF Koha.Preference('ElasticsearchMARCFormat') == 'ARRAY' %] >+ <input type="checkbox" name="whole_record"> >+ <label for="whole_record">Search entire MARC record</label> >+ [% END %] > [% FOREACH search_box IN search_boxes_loop %] > [% IF ( search_boxes_label ) %]<div style="text-indent: 4.5em;">[% ELSE %]<div>[% END %] > [% IF ( expanded_options ) %] >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 20589
:
74245
|
74249
|
74301
|
74373
|
74418
|
74419
|
82503
|
82544
|
83016
|
83019
|
87358
|
87411
|
87412
|
87415
|
87416
|
92454
|
92455
|
92456
|
92457
|
93238
|
93239
|
93240
|
93241
|
93247
|
93248
|
93249
|
93250
|
93251
|
93348
|
93349
|
93350
|
93351
|
93352
|
93353
|
93379
|
93380
|
93381
|
93382
|
93383
|
93384
|
93590
|
93624