|
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, |
|
|
210 |
}; |
| 211 |
$query_string->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); |
| 212 |
|
| 213 |
$res->{query} = { |
| 214 |
bool => { |
| 215 |
must => [ |
| 216 |
{query_string => $query_string} |
| 217 |
] |
| 211 |
} |
218 |
} |
| 212 |
}; |
219 |
}; |
| 213 |
$res->{query}->{query_string}->{type} = 'cross_fields' if C4::Context->preference('ElasticsearchCrossFields'); |
220 |
|
|
|
221 |
$res->{query}->{bool}->{should} = $options{field_match_boost_query} if $options{field_match_boost_query}; |
| 214 |
|
222 |
|
| 215 |
if ( $options{sort} ) { |
223 |
if ( $options{sort} ) { |
| 216 |
foreach my $sort ( @{ $options{sort} } ) { |
224 |
foreach my $sort ( @{ $options{sort} } ) { |
|
Lines 262-267
sub build_query_compat {
Link Here
|
| 262 |
$lang, $params ) |
270 |
$lang, $params ) |
| 263 |
= @_; |
271 |
= @_; |
| 264 |
|
272 |
|
|
|
273 |
my $field_match_boost_query = _build_field_match_boost_query({ operands => $operands, indexes => $indexes }); |
| 274 |
|
| 265 |
my $query; |
275 |
my $query; |
| 266 |
my $query_str = ''; |
276 |
my $query_str = ''; |
| 267 |
my $search_param_query_str = ''; |
277 |
my $search_param_query_str = ''; |
|
Lines 314-319
sub build_query_compat {
Link Here
|
| 314 |
$options{is_opac} = $params->{is_opac}; |
324 |
$options{is_opac} = $params->{is_opac}; |
| 315 |
$options{weighted_fields} = $params->{weighted_fields}; |
325 |
$options{weighted_fields} = $params->{weighted_fields}; |
| 316 |
$options{whole_record} = $params->{whole_record}; |
326 |
$options{whole_record} = $params->{whole_record}; |
|
|
327 |
$options{field_match_boost_query} = $field_match_boost_query if @$field_match_boost_query; |
| 317 |
$query = $self->build_query( $query_str, %options ); |
328 |
$query = $self->build_query( $query_str, %options ); |
| 318 |
} |
329 |
} |
| 319 |
|
330 |
|
|
Lines 348-353
sub build_query_compat {
Link Here
|
| 348 |
$limit, $limit_cgi, $limit_desc, undef, undef |
359 |
$limit, $limit_cgi, $limit_desc, undef, undef |
| 349 |
); |
360 |
); |
| 350 |
} |
361 |
} |
|
|
362 |
sub _build_field_match_boost_query { |
| 363 |
my ( $params ) = @_; |
| 364 |
my $indexes = $params->{indexes}; |
| 365 |
my $operands = $params->{operands}; |
| 366 |
|
| 367 |
my @boost_query; |
| 368 |
my $ea = each_array( @$operands, @$indexes ); |
| 369 |
while ( my ( $operand, $index ) = $ea->() ) { |
| 370 |
next unless $operand; |
| 371 |
$index = 'title-cover' if ( $index eq 'kw' || $index eq 'ti' || $index eq 'title' || !$index); |
| 372 |
push @boost_query, { match => { $index => { query => $operand } } }; |
| 373 |
} |
| 374 |
return \@boost_query; |
| 375 |
} |
| 351 |
|
376 |
|
| 352 |
=head2 build_authorities_query |
377 |
=head2 build_authorities_query |
| 353 |
|
378 |
|
| 354 |
- |
|
|