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 829-832
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori
Link Here
|
829 |
); |
831 |
); |
830 |
}; |
832 |
}; |
831 |
|
833 |
|
|
|
834 |
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents with IncludeSeeFromInSearches' => sub { |
835 |
|
836 |
plan tests => 4; |
837 |
|
838 |
t::lib::Mocks::mock_preference('marcflavour', 'MARC21'); |
839 |
t::lib::Mocks::mock_preference('IncludeSeeFromInSearches', '1'); |
840 |
|
841 |
my $builder = t::lib::TestBuilder->new; |
842 |
my $auth_type = $builder->build_object({ |
843 |
class => 'Koha::Authority::Types', |
844 |
value => { |
845 |
auth_tag_to_report => '150' |
846 |
} |
847 |
}); |
848 |
my $authority_record = MARC::Record->new(); |
849 |
$authority_record->append_fields( |
850 |
MARC::Field->new(150, '', '', a => 'Foo'), |
851 |
MARC::Field->new(450, '', '', a => 'Bar'), |
852 |
); |
853 |
my $authid = AddAuthority($authority_record, undef, $auth_type->authtypecode); |
854 |
|
855 |
my @mappings = ( |
856 |
{ |
857 |
name => 'subject', |
858 |
type => 'string', |
859 |
facet => 1, |
860 |
suggestible => 1, |
861 |
sort => undef, |
862 |
searchable => 1, |
863 |
marc_type => 'marc21', |
864 |
marc_field => '650a', |
865 |
} |
866 |
); |
867 |
|
868 |
my $se = Test::MockModule->new('Koha::SearchEngine::Elasticsearch'); |
869 |
$se->mock('_foreach_mapping', sub { |
870 |
my ($self, $sub) = @_; |
871 |
|
872 |
foreach my $map (@mappings) { |
873 |
$sub->( |
874 |
$map->{name}, |
875 |
$map->{type}, |
876 |
$map->{facet}, |
877 |
$map->{suggestible}, |
878 |
$map->{sort}, |
879 |
$map->{searchable}, |
880 |
$map->{marc_type}, |
881 |
$map->{marc_field} |
882 |
); |
883 |
} |
884 |
}); |
885 |
|
886 |
my $see = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }); |
887 |
|
888 |
my $marc_record_1 = MARC::Record->new(); |
889 |
$marc_record_1->leader(' cam 22 a 4500'); |
890 |
$marc_record_1->append_fields( |
891 |
MARC::Field->new('001', '123'), |
892 |
MARC::Field->new('245', '', '', a => 'Title'), |
893 |
MARC::Field->new('650', '', '', a => 'Foo', 9 => $authid), |
894 |
MARC::Field->new('999', '', '', c => '1234567'), |
895 |
); |
896 |
|
897 |
# sort_fields will call this and use the actual db values unless we call it first |
898 |
$see->get_elasticsearch_mappings(); |
899 |
|
900 |
my $docs = $see->marc_records_to_documents([$marc_record_1]); |
901 |
|
902 |
is_deeply($docs->[0]->{subject}, ['Foo', 'Bar'], 'subject should include "See from"'); |
903 |
is_deeply($docs->[0]->{subject__facet}, ['Foo'], 'subject__facet should not include "See from"'); |
904 |
is_deeply($docs->[0]->{subject__suggestion}, [{ input => 'Foo' }], 'subject__suggestion should not include "See from"'); |
905 |
is_deeply($docs->[0]->{subject__sort}, ['Foo'], 'subject__sort should not include "See from"'); |
906 |
}; |
907 |
|
832 |
$schema->storage->txn_rollback; |
908 |
$schema->storage->txn_rollback; |
833 |
- |
|
|