Lines 384-437
subtest 'build query from form subtests' => sub {
Link Here
|
384 |
}; |
384 |
}; |
385 |
|
385 |
|
386 |
subtest 'build_query with weighted fields tests' => sub { |
386 |
subtest 'build_query with weighted fields tests' => sub { |
387 |
plan tests => 2; |
387 |
plan tests => 4; |
388 |
|
388 |
|
389 |
my $qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'mydb' } ); |
389 |
$se->mock( '_load_elasticsearch_mappings', sub { |
390 |
my $db_builder = t::lib::TestBuilder->new(); |
390 |
return { |
391 |
|
391 |
biblios => { |
392 |
Koha::SearchFields->search({})->delete; |
392 |
abstract => { |
393 |
$clear_search_fields_cache->(); |
393 |
label => 'abstract', |
394 |
|
394 |
type => 'string', |
395 |
$db_builder->build({ |
395 |
opac => 1, |
396 |
source => 'SearchField', |
396 |
staff_client => 0, |
397 |
value => { |
397 |
mappings => [{ |
398 |
name => 'acqdate', |
398 |
marc_field => '520', |
399 |
label => 'acqdate', |
399 |
marc_type => 'marc21', |
400 |
weight => undef, |
400 |
}] |
401 |
staff_client => 1 |
401 |
}, |
402 |
} |
402 |
acqdate => { |
|
|
403 |
label => 'acqdate', |
404 |
type => 'string', |
405 |
opac => 0, |
406 |
staff_client => 1, |
407 |
mappings => [{ |
408 |
marc_field => '952d', |
409 |
marc_type => 'marc21', |
410 |
search => 0, |
411 |
}, { |
412 |
marc_field => '9955', |
413 |
marc_type => 'marc21', |
414 |
search => 0, |
415 |
}] |
416 |
}, |
417 |
title => { |
418 |
label => 'title', |
419 |
type => 'string', |
420 |
opac => 0, |
421 |
staff_client => 1, |
422 |
mappings => [{ |
423 |
marc_field => '130', |
424 |
marc_type => 'marc21' |
425 |
}] |
426 |
}, |
427 |
subject => { |
428 |
label => 'subject', |
429 |
type => 'string', |
430 |
opac => 0, |
431 |
staff_client => 1, |
432 |
mappings => [{ |
433 |
marc_field => '600a', |
434 |
marc_type => 'marc21' |
435 |
}] |
436 |
} |
437 |
} |
438 |
}; |
403 |
}); |
439 |
}); |
404 |
|
440 |
|
405 |
$db_builder->build({ |
441 |
my $qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'biblios' } ); |
406 |
source => 'SearchField', |
442 |
Koha::SearchFields->search({})->delete; |
407 |
value => { |
443 |
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings(); |
408 |
name => 'title', |
|
|
409 |
label => 'title', |
410 |
weight => 25, |
411 |
staff_client => 1 |
412 |
} |
413 |
}); |
414 |
|
444 |
|
415 |
$db_builder->build({ |
445 |
my $search_field; |
416 |
source => 'SearchField', |
446 |
$search_field = Koha::SearchFields->find({ name => 'title' }); |
417 |
value => { |
447 |
$search_field->update({ weight => 25.0 }); |
418 |
name => 'subject', |
448 |
$search_field = Koha::SearchFields->find({ name => 'subject' }); |
419 |
label => 'subject', |
449 |
$search_field->update({ weight => 15.5 }); |
420 |
weight => 15, |
450 |
$clear_search_fields_cache->(); |
421 |
staff_client => 1 |
|
|
422 |
} |
423 |
}); |
424 |
|
451 |
|
425 |
my ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, |
452 |
my ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, |
426 |
undef, undef, undef, { weighted_fields => 1 }); |
453 |
undef, undef, undef, { weighted_fields => 1 }); |
427 |
|
454 |
|
428 |
my $fields = $query->{query}{query_string}{fields}; |
455 |
my $fields = $query->{query}{query_string}{fields}; |
429 |
|
456 |
|
|
|
457 |
is(@{$fields}, 2, 'Search field with no searchable mappings has been excluded'); |
458 |
|
430 |
my @found = grep { $_ eq 'title^25.00' } @{$fields}; |
459 |
my @found = grep { $_ eq 'title^25.00' } @{$fields}; |
431 |
is(@found, 1, 'Search field is title has correct weight'); # Fails |
460 |
is(@found, 1, 'Search field title has correct weight'); |
|
|
461 |
|
462 |
@found = grep { $_ eq 'subject^15.50' } @{$fields}; |
463 |
is(@found, 1, 'Search field subject has correct weight'); |
464 |
|
465 |
( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, |
466 |
undef, undef, undef, { weighted_fields => 1, is_opac => 1 }); |
432 |
|
467 |
|
433 |
@found = grep { $_ eq 'subject^15.00' } @{$fields}; |
468 |
$fields = $query->{query}{query_string}{fields}; |
434 |
is(@found, 1, 'Search field subject has correct weight'); # Fails |
469 |
|
|
|
470 |
is_deeply( |
471 |
$fields, |
472 |
['abstract'], |
473 |
'Only OPAC search fields are used when opac search is performed' |
474 |
); |
435 |
}; |
475 |
}; |
436 |
|
476 |
|
437 |
subtest "_convert_sort_fields() tests" => sub { |
477 |
subtest "_convert_sort_fields() tests" => sub { |
438 |
- |
|
|