|
Lines 203-219
sub build_query {
Link Here
|
| 203 |
if ( $options{whole_record} ) { |
203 |
if ( $options{whole_record} ) { |
| 204 |
push @$fields, 'marc_data_array.*'; |
204 |
push @$fields, 'marc_data_array.*'; |
| 205 |
} |
205 |
} |
| 206 |
$res->{query} = { |
206 |
my $query_string = { |
| 207 |
query_string => { |
207 |
query => $query, |
| 208 |
query => $query, |
208 |
fuzziness => $fuzzy_enabled ? 'auto' : '0', |
| 209 |
fuzziness => $fuzzy_enabled ? 'auto' : '0', |
209 |
default_operator => 'AND', |
| 210 |
default_operator => 'AND', |
210 |
fields => $fields, |
| 211 |
fields => $fields, |
211 |
lenient => JSON::true, |
| 212 |
lenient => JSON::true, |
212 |
analyze_wildcard => JSON::true, |
| 213 |
analyze_wildcard => JSON::true, |
|
|
| 214 |
} |
| 215 |
}; |
213 |
}; |
| 216 |
$res->{query}->{query_string}->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); |
214 |
$query_string->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); |
|
|
215 |
|
| 216 |
$res->{query} = { bool => { must => [ { query_string => $query_string } ] } }; |
| 217 |
|
| 218 |
$res->{query}->{bool}->{should} = $options{field_match_boost_query} if $options{field_match_boost_query}; |
| 217 |
|
219 |
|
| 218 |
if ( $options{sort} ) { |
220 |
if ( $options{sort} ) { |
| 219 |
foreach my $sort ( @{ $options{sort} } ) { |
221 |
foreach my $sort ( @{ $options{sort} } ) { |
|
Lines 280-285
sub build_query_compat {
Link Here
|
| 280 |
} else { |
282 |
} else { |
| 281 |
my @sort_params = $self->_convert_sort_fields(@$sort_by); |
283 |
my @sort_params = $self->_convert_sort_fields(@$sort_by); |
| 282 |
my @index_params = $self->_convert_index_fields(@$indexes); |
284 |
my @index_params = $self->_convert_index_fields(@$indexes); |
|
|
285 |
my $field_match_boost_query = |
| 286 |
C4::Context->preference('ESBoostFieldMatch') |
| 287 |
? $self->_build_field_match_boost_query( { operands => $operands, indexes => \@index_params } ) |
| 288 |
: []; |
| 283 |
$limits = $self->_fix_limit_special_cases($orig_limits); |
289 |
$limits = $self->_fix_limit_special_cases($orig_limits); |
| 284 |
if ( $params->{suppress} ) { push @$limits, "suppress:false"; } |
290 |
if ( $params->{suppress} ) { push @$limits, "suppress:false"; } |
| 285 |
|
291 |
|
|
Lines 320-331
sub build_query_compat {
Link Here
|
| 320 |
# If there's no query on the left, let's remove the junk left behind |
326 |
# If there's no query on the left, let's remove the junk left behind |
| 321 |
$query_str =~ s/^ AND //; |
327 |
$query_str =~ s/^ AND //; |
| 322 |
my %options; |
328 |
my %options; |
| 323 |
$options{sort} = \@sort_params; |
329 |
$options{sort} = \@sort_params; |
| 324 |
$options{is_opac} = $params->{is_opac}; |
330 |
$options{is_opac} = $params->{is_opac}; |
| 325 |
$options{weighted_fields} = $params->{weighted_fields}; |
331 |
$options{weighted_fields} = $params->{weighted_fields}; |
| 326 |
$options{whole_record} = $params->{whole_record}; |
332 |
$options{whole_record} = $params->{whole_record}; |
| 327 |
$options{skip_facets} = $params->{skip_facets}; |
333 |
$options{skip_facets} = $params->{skip_facets}; |
| 328 |
$query = $self->build_query( $query_str, %options ); |
334 |
$options{field_match_boost_query} = $field_match_boost_query if @$field_match_boost_query; |
|
|
335 |
$query = $self->build_query( $query_str, %options ); |
| 329 |
} |
336 |
} |
| 330 |
|
337 |
|
| 331 |
# We roughly emulate the CGI parameters of the zebra query builder |
338 |
# We roughly emulate the CGI parameters of the zebra query builder |
|
Lines 361-366
sub build_query_compat {
Link Here
|
| 361 |
); |
368 |
); |
| 362 |
} |
369 |
} |
| 363 |
|
370 |
|
|
|
371 |
=head2 _build_field_match_boost_query |
| 372 |
|
| 373 |
my ($query, $query_str) = $builder->_build_field_match_boost_query({ operands => \@operands, indexes => \@indexes) |
| 374 |
|
| 375 |
This will build an array of match queries for terms and indexes passed in and return a reference to the array. |
| 376 |
|
| 377 |
=cut |
| 378 |
|
| 379 |
sub _build_field_match_boost_query { |
| 380 |
my ( $self, $params ) = @_; |
| 381 |
my $indexes = $params->{indexes}; |
| 382 |
my $operands = $params->{operands}; |
| 383 |
|
| 384 |
my @boost_query; |
| 385 |
my $ea = each_array( @$operands, @$indexes ); |
| 386 |
while ( my ( $operand, $index ) = $ea->() ) { |
| 387 |
next unless $operand; |
| 388 |
$index = $index->{field} if ref $index eq 'HASH'; |
| 389 |
$index = 'title-cover' if ( !$index || $index eq 'kw' || $index eq 'ti' || $index eq 'title' ); |
| 390 |
push @boost_query, { match => { $index => { query => $operand } } }; |
| 391 |
} |
| 392 |
return \@boost_query; |
| 393 |
} |
| 394 |
|
| 364 |
=head2 build_authorities_query |
395 |
=head2 build_authorities_query |
| 365 |
|
396 |
|
| 366 |
my $query = $builder->build_authorities_query(\%search); |
397 |
my $query = $builder->build_authorities_query(\%search); |