|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 6; |
20 |
use Test::More tests => 7; |
| 21 |
use Test::Exception; |
21 |
use Test::Exception; |
| 22 |
|
22 |
|
| 23 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
|
Lines 29-34
use MARC::Record;
Link Here
|
| 29 |
use Try::Tiny; |
29 |
use Try::Tiny; |
| 30 |
use List::Util qw( any ); |
30 |
use List::Util qw( any ); |
| 31 |
|
31 |
|
|
|
32 |
use C4::AuthoritiesMarc; |
| 33 |
|
| 32 |
use Koha::SearchEngine::Elasticsearch; |
34 |
use Koha::SearchEngine::Elasticsearch; |
| 33 |
use Koha::SearchEngine::Elasticsearch::Search; |
35 |
use Koha::SearchEngine::Elasticsearch::Search; |
| 34 |
|
36 |
|
|
Lines 850-853
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori
Link Here
|
| 850 |
|
852 |
|
| 851 |
}; |
853 |
}; |
| 852 |
|
854 |
|
|
|
855 |
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents with IncludeSeeFromInSearches' => sub { |
| 856 |
|
| 857 |
plan tests => 4; |
| 858 |
|
| 859 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
| 860 |
t::lib::Mocks::mock_preference('IncludeSeeFromInSearches', '1'); |
| 861 |
|
| 862 |
my $builder = t::lib::TestBuilder->new; |
| 863 |
my $auth_type = $builder->build_object({ |
| 864 |
class => 'Koha::Authority::Types', |
| 865 |
value => { |
| 866 |
auth_tag_to_report => '150' |
| 867 |
} |
| 868 |
}); |
| 869 |
my $authority_record = MARC::Record->new(); |
| 870 |
$authority_record->append_fields( |
| 871 |
MARC::Field->new(150, '', '', a => 'Foo'), |
| 872 |
MARC::Field->new(450, '', '', a => 'Bar'), |
| 873 |
); |
| 874 |
my $authid = AddAuthority($authority_record, undef, $auth_type->authtypecode); |
| 875 |
|
| 876 |
my @mappings = ( |
| 877 |
{ |
| 878 |
name => 'subject', |
| 879 |
type => 'string', |
| 880 |
facet => 1, |
| 881 |
suggestible => 1, |
| 882 |
sort => undef, |
| 883 |
searchable => 1, |
| 884 |
marc_type => 'marc21', |
| 885 |
marc_field => '650a', |
| 886 |
} |
| 887 |
); |
| 888 |
|
| 889 |
my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); |
| 890 |
$se->mock('_foreach_mapping', sub { |
| 891 |
my ($self, $sub) = @_; |
| 892 |
|
| 893 |
foreach my $map (@mappings) { |
| 894 |
$sub->( |
| 895 |
$map->{name}, |
| 896 |
$map->{type}, |
| 897 |
$map->{facet}, |
| 898 |
$map->{suggestible}, |
| 899 |
$map->{sort}, |
| 900 |
$map->{searchable}, |
| 901 |
$map->{marc_type}, |
| 902 |
$map->{marc_field} |
| 903 |
); |
| 904 |
} |
| 905 |
}); |
| 906 |
|
| 907 |
my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); |
| 908 |
|
| 909 |
my $marc_record_1 = MARC::Record->new(); |
| 910 |
$marc_record_1->leader(' cam 22 a 4500'); |
| 911 |
$marc_record_1->append_fields( |
| 912 |
MARC::Field->new('001', '123'), |
| 913 |
MARC::Field->new('245', '', '', a => 'Title'), |
| 914 |
MARC::Field->new('650', '', '', a => 'Foo', 9 => $authid), |
| 915 |
MARC::Field->new('999', '', '', c => '1234567'), |
| 916 |
); |
| 917 |
|
| 918 |
# sort_fields will call this and use the actual db values unless we call it first |
| 919 |
$see->get_elasticsearch_mappings(); |
| 920 |
|
| 921 |
my $docs = $see->marc_records_to_documents([$marc_record_1]); |
| 922 |
|
| 923 |
is_deeply($docs->[0]->{subject}, ['Foo', 'Bar'], 'subject should include "See from"'); |
| 924 |
is_deeply($docs->[0]->{subject__facet}, ['Foo'], 'subject__facet should not include "See from"'); |
| 925 |
is_deeply($docs->[0]->{subject__suggestion}, [{ input => 'Foo' }], 'subject__suggestion should not include "See from"'); |
| 926 |
is_deeply($docs->[0]->{subject__sort}, ['Foo'], 'subject__sort should not include "See from"'); |
| 927 |
}; |
| 928 |
|
| 853 |
$schema->storage->txn_rollback; |
929 |
$schema->storage->txn_rollback; |
| 854 |
- |
|
|