Lines 44-53
use JSON;
Link Here
|
44 |
use List::MoreUtils qw( each_array ); |
44 |
use List::MoreUtils qw( each_array ); |
45 |
use Modern::Perl; |
45 |
use Modern::Perl; |
46 |
use URI::Escape qw( uri_escape_utf8 ); |
46 |
use URI::Escape qw( uri_escape_utf8 ); |
|
|
47 |
use YAML::XS; |
47 |
|
48 |
|
48 |
use C4::Context; |
49 |
use C4::Context; |
49 |
use Koha::Exceptions; |
50 |
use Koha::Exceptions; |
50 |
use Koha::Caches; |
51 |
use Koha::Caches; |
|
|
52 |
use Koha::Logger; |
51 |
|
53 |
|
52 |
our %index_field_convert = ( |
54 |
our %index_field_convert = ( |
53 |
'kw' => '', |
55 |
'kw' => '', |
Lines 197-203
sub build_query {
Link Here
|
197 |
if ($options{whole_record}) { |
199 |
if ($options{whole_record}) { |
198 |
push @$fields, 'marc_data_array.*'; |
200 |
push @$fields, 'marc_data_array.*'; |
199 |
} |
201 |
} |
200 |
$res->{query} = { |
202 |
$res->{query}->{function_score}->{query} = { |
201 |
query_string => { |
203 |
query_string => { |
202 |
query => $query, |
204 |
query => $query, |
203 |
fuzziness => $fuzzy_enabled ? 'auto' : '0', |
205 |
fuzziness => $fuzzy_enabled ? 'auto' : '0', |
Lines 207-213
sub build_query {
Link Here
|
207 |
analyze_wildcard => JSON::true, |
209 |
analyze_wildcard => JSON::true, |
208 |
} |
210 |
} |
209 |
}; |
211 |
}; |
210 |
$res->{query}->{query_string}->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); |
212 |
|
|
|
213 |
# Trying to get the scoring functions from the syspref or set as empty arrayref |
214 |
my $scoring_functions = []; |
215 |
eval { |
216 |
$scoring_functions = YAML::XS::Load( C4::Context->preference('ElasticsearchFunctionScore') ) |
217 |
if ( $options{weighted_fields} && C4::Context->preference('ElasticsearchFunctionScore') ); |
218 |
1; |
219 |
} or do { |
220 |
my $e = $@; |
221 |
Koha::Logger->get->warn("Malformed yaml in ElasticsearchFunctionScore $e/n"); |
222 |
}; |
223 |
$res->{query}->{function_score}->{functions} = $scoring_functions; |
224 |
|
225 |
$res->{query}->{function_score}->{query}->{query_string}->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); |
211 |
|
226 |
|
212 |
if ( $options{sort} ) { |
227 |
if ( $options{sort} ) { |
213 |
foreach my $sort ( @{ $options{sort} } ) { |
228 |
foreach my $sort ( @{ $options{sort} } ) { |
214 |
- |
|
|