View | Details | Raw Unified | Return to bug 26903
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/Indexer.pm (-2 / +3 lines)
Lines 101-107 sub update_index { Link Here
101
101
102
    my $documents = $self->marc_records_to_documents($records);
102
    my $documents = $self->marc_records_to_documents($records);
103
    my @body;
103
    my @body;
104
105
    for (my $i = 0; $i < scalar @$biblionums; $i++) {
104
    for (my $i = 0; $i < scalar @$biblionums; $i++) {
106
        my $id = $biblionums->[$i];
105
        my $id = $biblionums->[$i];
107
        my $document = $documents->[$i];
106
        my $document = $documents->[$i];
Lines 302-308 sub index_records { Link Here
302
    $records = [$records] if ref $records ne 'ARRAY' && defined $records;
301
    $records = [$records] if ref $records ne 'ARRAY' && defined $records;
303
    if ( $op eq 'specialUpdate' ) {
302
    if ( $op eq 'specialUpdate' ) {
304
        my $index_record_numbers;
303
        my $index_record_numbers;
305
        unless ($records) {
304
        if ($records){
305
            $index_record_numbers = $record_numbers;
306
        } else {
306
            foreach my $record_number ( @$record_numbers ){
307
            foreach my $record_number ( @$record_numbers ){
307
                my $record = _get_record( $record_number, $server );
308
                my $record = _get_record( $record_number, $server );
308
                if( $record ){
309
                if( $record ){
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Indexer.t (-3 / +32 lines)
Lines 19-27 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 2;
22
use Test::More tests => 3;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Warn;
24
use t::lib::Mocks;
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
25
27
26
use MARC::Record;
28
use MARC::Record;
27
29
Lines 35-43 SKIP: { Link Here
35
37
36
    eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; };
38
    eval { Koha::SearchEngine::Elasticsearch->get_elasticsearch_params; };
37
39
38
    skip 'Elasticsearch configuration not available', 1
40
    skip 'Elasticsearch configuration not available', 2
39
        if $@;
41
        if $@;
40
42
43
my $builder = t::lib::TestBuilder->new;
44
my $biblio = $builder->build_sample_biblio; # create biblio before we start mocking to avoid trouble indexing on creation
45
41
subtest 'create_index() tests' => sub {
46
subtest 'create_index() tests' => sub {
42
    plan tests => 6;
47
    plan tests => 6;
43
    my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' );
48
    my $se = Test::MockModule->new( 'Koha::SearchEngine::Elasticsearch' );
Lines 80-83 subtest 'create_index() tests' => sub { Link Here
80
        'Dropping the index'
85
        'Dropping the index'
81
    );
86
    );
82
};
87
};
88
89
subtest 'index_records() tests' => sub {
90
    plan tests => 2;
91
    my $mock_index = Test::MockModule->new("Koha::SearchEngine::Elasticsearch::Indexer");
92
    $mock_index->mock( update_index => sub {
93
        my ($self, $record_ids, $records) = @_;
94
        warn $record_ids->[0] . $records->[0]->as_usmarc;
95
    });
96
97
    my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'authorities' });
98
99
    my $marc_record = MARC::Record->new();
100
    $marc_record->append_fields(
101
        MARC::Field->new('001', '1234567'),
102
        MARC::Field->new('100', '', '', 'a' => 'Rosenstock, Jeff'),
103
    );
104
    warning_is{ $indexer->index_records([42],'specialUpdate','authorityserver',[$marc_record]); } "42".$marc_record->as_usmarc,
105
        "When passing record and ids to index_records they are correctly passed through to update_index";
106
107
    $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new({ 'index' => 'biblios' });
108
    $marc_record = C4::Biblio::GetMarcBiblio({ biblionumber => $biblio->biblionumber, embed_items  => 1 });
109
    warning_is{ $indexer->index_records([$biblio->biblionumber],'specialUpdate','biblioserver'); } $biblio->biblionumber.$marc_record->as_usmarc,
110
        "When passing id only to index_records the marc record is fetched and passed through to update_index";
111
};
112
83
}
113
}
84
- 

Return to bug 26903