|
Lines 200-216
sub build_query {
Link Here
|
| 200 |
if ($options{whole_record}) { |
200 |
if ($options{whole_record}) { |
| 201 |
push @$fields, 'marc_data_array.*'; |
201 |
push @$fields, 'marc_data_array.*'; |
| 202 |
} |
202 |
} |
| 203 |
$res->{query} = { |
203 |
my $query_string = { |
| 204 |
query_string => { |
|
|
| 205 |
query => $query, |
204 |
query => $query, |
| 206 |
fuzziness => $fuzzy_enabled ? 'auto' : '0', |
205 |
fuzziness => $fuzzy_enabled ? 'auto' : '0', |
| 207 |
default_operator => 'AND', |
206 |
default_operator => 'AND', |
| 208 |
fields => $fields, |
207 |
fields => $fields, |
| 209 |
lenient => JSON::true, |
208 |
lenient => JSON::true, |
| 210 |
analyze_wildcard => JSON::true, |
209 |
analyze_wildcard => JSON::true, |
| 211 |
} |
210 |
}; |
| 212 |
}; |
211 |
$query_string->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); |
| 213 |
$res->{query}->{query_string}->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); |
212 |
|
|
|
213 |
$res->{query} = { bool => { must => [ { query_string => $query_string } ] } }; |
| 214 |
|
| 215 |
$res->{query}->{bool}->{should} = $options{field_match_boost_query} if $options{field_match_boost_query}; |
| 214 |
|
216 |
|
| 215 |
if ( $options{sort} ) { |
217 |
if ( $options{sort} ) { |
| 216 |
foreach my $sort ( @{ $options{sort} } ) { |
218 |
foreach my $sort ( @{ $options{sort} } ) { |
|
Lines 262-267
sub build_query_compat {
Link Here
|
| 262 |
$lang, $params ) |
264 |
$lang, $params ) |
| 263 |
= @_; |
265 |
= @_; |
| 264 |
|
266 |
|
|
|
267 |
|
| 265 |
my $query; |
268 |
my $query; |
| 266 |
my $query_str = ''; |
269 |
my $query_str = ''; |
| 267 |
my $search_param_query_str = ''; |
270 |
my $search_param_query_str = ''; |
|
Lines 272-278
sub build_query_compat {
Link Here
|
| 272 |
} else { |
275 |
} else { |
| 273 |
my @sort_params = $self->_convert_sort_fields(@$sort_by); |
276 |
my @sort_params = $self->_convert_sort_fields(@$sort_by); |
| 274 |
my @index_params = $self->_convert_index_fields(@$indexes); |
277 |
my @index_params = $self->_convert_index_fields(@$indexes); |
| 275 |
$limits = $self->_fix_limit_special_cases($orig_limits); |
278 |
my $field_match_boost_query = |
|
|
279 |
C4::Context->preference('ESBoostFieldMatch') |
| 280 |
? $self->_build_field_match_boost_query( { operands => $operands, indexes => \@index_params } ) |
| 281 |
: []; |
| 282 |
$limits = $self->_fix_limit_special_cases($orig_limits); |
| 276 |
if ( $params->{suppress} ) { push @$limits, "suppress:false"; } |
283 |
if ( $params->{suppress} ) { push @$limits, "suppress:false"; } |
| 277 |
# Merge the indexes in with the search terms and the operands so that |
284 |
# Merge the indexes in with the search terms and the operands so that |
| 278 |
# each search thing is a handy unit. |
285 |
# each search thing is a handy unit. |
|
Lines 314-319
sub build_query_compat {
Link Here
|
| 314 |
$options{is_opac} = $params->{is_opac}; |
321 |
$options{is_opac} = $params->{is_opac}; |
| 315 |
$options{weighted_fields} = $params->{weighted_fields}; |
322 |
$options{weighted_fields} = $params->{weighted_fields}; |
| 316 |
$options{whole_record} = $params->{whole_record}; |
323 |
$options{whole_record} = $params->{whole_record}; |
|
|
324 |
$options{field_match_boost_query} = $field_match_boost_query if @$field_match_boost_query; |
| 317 |
$query = $self->build_query( $query_str, %options ); |
325 |
$query = $self->build_query( $query_str, %options ); |
| 318 |
} |
326 |
} |
| 319 |
|
327 |
|
|
Lines 349-354
sub build_query_compat {
Link Here
|
| 349 |
); |
357 |
); |
| 350 |
} |
358 |
} |
| 351 |
|
359 |
|
|
|
360 |
=head2 _build_field_match_boost_query |
| 361 |
|
| 362 |
my ($query, $query_str) = $builder->_build_field_match_boost_query({ operands => \@operands, indexes => \@indexes) |
| 363 |
|
| 364 |
This will build an array of match queries for terms and indexes passed in and return a reference to the array. |
| 365 |
|
| 366 |
=cut |
| 367 |
|
| 368 |
sub _build_field_match_boost_query { |
| 369 |
my ( $self, $params ) = @_; |
| 370 |
my $indexes = $params->{indexes}; |
| 371 |
my $operands = $params->{operands}; |
| 372 |
|
| 373 |
my @boost_query; |
| 374 |
my $ea = each_array( @$operands, @$indexes ); |
| 375 |
while ( my ( $operand, $index ) = $ea->() ) { |
| 376 |
next unless $operand; |
| 377 |
$index = $index->{field} if ref $index eq 'HASH'; |
| 378 |
$index = 'title-cover' if ( !$index || $index eq 'kw' || $index eq 'ti' || $index eq 'title' ); |
| 379 |
push @boost_query, { match => { $index => { query => $operand } } }; |
| 380 |
} |
| 381 |
return \@boost_query; |
| 382 |
} |
| 383 |
|
| 352 |
=head2 build_authorities_query |
384 |
=head2 build_authorities_query |
| 353 |
|
385 |
|
| 354 |
my $query = $builder->build_authorities_query(\%search); |
386 |
my $query = $builder->build_authorities_query(\%search); |