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