|
Lines 458-511
subtest 'build query from form subtests' => sub {
Link Here
|
| 458 |
}; |
458 |
}; |
| 459 |
|
459 |
|
| 460 |
subtest 'build_query with weighted fields tests' => sub { |
460 |
subtest 'build_query with weighted fields tests' => sub { |
| 461 |
plan tests => 2; |
461 |
plan tests => 4; |
| 462 |
|
462 |
|
| 463 |
my $qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'mydb' } ); |
463 |
$se->mock( '_load_elasticsearch_mappings', sub { |
| 464 |
my $db_builder = t::lib::TestBuilder->new(); |
464 |
return { |
| 465 |
|
465 |
biblios => { |
| 466 |
Koha::SearchFields->search({})->delete; |
466 |
abstract => { |
| 467 |
$clear_search_fields_cache->(); |
467 |
label => 'abstract', |
| 468 |
|
468 |
type => 'string', |
| 469 |
$db_builder->build({ |
469 |
opac => 1, |
| 470 |
source => 'SearchField', |
470 |
staff_client => 0, |
| 471 |
value => { |
471 |
mappings => [{ |
| 472 |
name => 'acqdate', |
472 |
marc_field => '520', |
| 473 |
label => 'acqdate', |
473 |
marc_type => 'marc21', |
| 474 |
weight => undef, |
474 |
}] |
| 475 |
staff_client => 1 |
475 |
}, |
| 476 |
} |
476 |
acqdate => { |
|
|
477 |
label => 'acqdate', |
| 478 |
type => 'string', |
| 479 |
opac => 0, |
| 480 |
staff_client => 1, |
| 481 |
mappings => [{ |
| 482 |
marc_field => '952d', |
| 483 |
marc_type => 'marc21', |
| 484 |
search => 0, |
| 485 |
}, { |
| 486 |
marc_field => '9955', |
| 487 |
marc_type => 'marc21', |
| 488 |
search => 0, |
| 489 |
}] |
| 490 |
}, |
| 491 |
title => { |
| 492 |
label => 'title', |
| 493 |
type => 'string', |
| 494 |
opac => 0, |
| 495 |
staff_client => 1, |
| 496 |
mappings => [{ |
| 497 |
marc_field => '130', |
| 498 |
marc_type => 'marc21' |
| 499 |
}] |
| 500 |
}, |
| 501 |
subject => { |
| 502 |
label => 'subject', |
| 503 |
type => 'string', |
| 504 |
opac => 0, |
| 505 |
staff_client => 1, |
| 506 |
mappings => [{ |
| 507 |
marc_field => '600a', |
| 508 |
marc_type => 'marc21' |
| 509 |
}] |
| 510 |
} |
| 511 |
} |
| 512 |
}; |
| 477 |
}); |
513 |
}); |
| 478 |
|
514 |
|
| 479 |
$db_builder->build({ |
515 |
my $qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new( { index => 'biblios' } ); |
| 480 |
source => 'SearchField', |
516 |
Koha::SearchFields->search({})->delete; |
| 481 |
value => { |
517 |
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings(); |
| 482 |
name => 'title', |
|
|
| 483 |
label => 'title', |
| 484 |
weight => 25, |
| 485 |
staff_client => 1 |
| 486 |
} |
| 487 |
}); |
| 488 |
|
518 |
|
| 489 |
$db_builder->build({ |
519 |
my $search_field; |
| 490 |
source => 'SearchField', |
520 |
$search_field = Koha::SearchFields->find({ name => 'title' }); |
| 491 |
value => { |
521 |
$search_field->update({ weight => 25.0 }); |
| 492 |
name => 'subject', |
522 |
$search_field = Koha::SearchFields->find({ name => 'subject' }); |
| 493 |
label => 'subject', |
523 |
$search_field->update({ weight => 15.5 }); |
| 494 |
weight => 15, |
524 |
$clear_search_fields_cache->(); |
| 495 |
staff_client => 1 |
|
|
| 496 |
} |
| 497 |
}); |
| 498 |
|
525 |
|
| 499 |
my ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, |
526 |
my ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, |
| 500 |
undef, undef, undef, { weighted_fields => 1 }); |
527 |
undef, undef, undef, { weighted_fields => 1 }); |
| 501 |
|
528 |
|
| 502 |
my $fields = $query->{query}{query_string}{fields}; |
529 |
my $fields = $query->{query}{query_string}{fields}; |
| 503 |
|
530 |
|
|
|
531 |
is(@{$fields}, 2, 'Search field with no searchable mappings has been excluded'); |
| 532 |
|
| 504 |
my @found = grep { $_ eq 'title^25.00' } @{$fields}; |
533 |
my @found = grep { $_ eq 'title^25.00' } @{$fields}; |
| 505 |
is(@found, 1, 'Search field is title has correct weight'); # Fails |
534 |
is(@found, 1, 'Search field title has correct weight'); |
|
|
535 |
|
| 536 |
@found = grep { $_ eq 'subject^15.50' } @{$fields}; |
| 537 |
is(@found, 1, 'Search field subject has correct weight'); |
| 538 |
|
| 539 |
( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, |
| 540 |
undef, undef, undef, { weighted_fields => 1, is_opac => 1 }); |
| 506 |
|
541 |
|
| 507 |
@found = grep { $_ eq 'subject^15.00' } @{$fields}; |
542 |
$fields = $query->{query}{query_string}{fields}; |
| 508 |
is(@found, 1, 'Search field subject has correct weight'); # Fails |
543 |
|
|
|
544 |
is_deeply( |
| 545 |
$fields, |
| 546 |
['abstract'], |
| 547 |
'Only OPAC search fields are used when opac search is performed' |
| 548 |
); |
| 509 |
}; |
549 |
}; |
| 510 |
|
550 |
|
| 511 |
subtest "_convert_sort_fields() tests" => sub { |
551 |
subtest "_convert_sort_fields() tests" => sub { |
| 512 |
- |
|
|