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

(-)a/C4/AuthoritiesMarc.pm (-1 / +1 lines)
Lines 628-634 sub AddAuthority { Link Here
628
    $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) );
628
    $record->insert_fields_ordered( MARC::Field->new( '001', $authid ) );
629
    # Update
629
    # Update
630
    $dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr;
630
    $dbh->do( "UPDATE auth_header SET authtypecode=?, marc=?, marcxml=? WHERE authid=?", undef, $authtypecode, $record->as_usmarc, $record->as_xml_record($format), $authid ) or die $DBI::errstr;
631
    ModZebra( $authid, 'specialUpdate', 'authorityserver', { record => $record, authtypecode => $authtypecode } );
631
    ModZebra( $authid, 'specialUpdate', 'authorityserver', $record );
632
632
633
    return ( $authid );
633
    return ( $authid );
634
}
634
}
(-)a/C4/Biblio.pm (-6 / +4 lines)
Lines 2497-2504 $op is specialUpdate or recordDelete, and is used to know what we want to do Link Here
2497
2497
2498
$server is the server that we want to update
2498
$server is the server that we want to update
2499
2499
2500
$record is a hash including the authtypecode and updated MARC record. This is only used for
2500
$record is the updated MARC record. If it's not supplied
2501
Elasticsearch authorities. If it's not supplied a biblio will be loaded from the database.
2501
and is needed it will be loaded from the database.
2502
2502
2503
=cut
2503
=cut
2504
2504
Lines 2518-2531 sub ModZebra { Link Here
2518
            }
2518
            }
2519
        );
2519
        );
2520
        if ( $op eq 'specialUpdate' ) {
2520
        if ( $op eq 'specialUpdate' ) {
2521
            if ($record) {
2521
            unless ($record) {
2522
                $indexer->update_index_background( [$biblionumber], [$record] );
2523
            } else {
2524
                $record = GetMarcBiblio({
2522
                $record = GetMarcBiblio({
2525
                    biblionumber => $biblionumber,
2523
                    biblionumber => $biblionumber,
2526
                    embed_items  => 1 });
2524
                    embed_items  => 1 });
2527
                $indexer->update_index_background( [$biblionumber], [{ record => $record }] );
2528
            }
2525
            }
2526
            $indexer->update_index_background( [$biblionumber], [$record] );
2529
        }
2527
        }
2530
        elsif ( $op eq 'recordDelete' ) {
2528
        elsif ( $op eq 'recordDelete' ) {
2531
            $indexer->delete_index_background( [$biblionumber] );
2529
            $indexer->delete_index_background( [$biblionumber] );
(-)a/Koha/SearchEngine/Elasticsearch.pm (-3 / +4 lines)
Lines 28-33 use Koha::SearchFields; Link Here
28
use Koha::SearchMarcMaps;
28
use Koha::SearchMarcMaps;
29
use Koha::Caches;
29
use Koha::Caches;
30
use C4::Heading;
30
use C4::Heading;
31
use C4::AuthoritiesMarc;
31
32
32
use Carp;
33
use Carp;
33
use Clone qw(clone);
34
use Clone qw(clone);
Lines 536-547 sub marc_records_to_documents { Link Here
536
    foreach my $record (@{$records}) {
537
    foreach my $record (@{$records}) {
537
        my $record_document = {};
538
        my $record_document = {};
538
539
539
        if ( defined $record->{authtypecode} ){
540
        if ( $self->index eq 'authorities' ){
540
            my $field = $record->{record}->field( $auth_match_headings{ $record->{authtypecode} } );
541
            my $authtypecode = GuessAuthTypeCode( $record );
542
            my $field = $record->field( $auth_match_headings{ $authtypecode } );
541
            my $heading = C4::Heading->new_from_field( $field, undef, 1 ); #new auth heading
543
            my $heading = C4::Heading->new_from_field( $field, undef, 1 ); #new auth heading
542
            push @{$record_document->{'match-heading'}}, $heading->search_form if $heading;
544
            push @{$record_document->{'match-heading'}}, $heading->search_form if $heading;
543
        }
545
        }
544
        $record = $record->{record};
545
546
546
        my $mappings = $rules->{leader};
547
        my $mappings = $rules->{leader};
547
        if ($mappings) {
548
        if ($mappings) {
(-)a/misc/search_tools/rebuild_elasticsearch.pl (-5 / +3 lines)
Lines 275-284 sub _do_reindex { Link Here
275
    my $commit_count = $commit;
275
    my $commit_count = $commit;
276
    my ( @id_buffer, @commit_buffer );
276
    my ( @id_buffer, @commit_buffer );
277
    while ( my $record = $next->() ) {
277
    while ( my $record = $next->() ) {
278
        my $id     = $record->id;
278
        my $id     = $record->id // $record->authid;
279
        my $record_prepped;
279
        my $record = $record->record;
280
        $record_prepped->{authtypecode} = $record->authtypecode if ref $record eq 'Koha::MetadataRecord::Authority';
281
        $record_prepped->{record} = $record->record;
282
        $count++;
280
        $count++;
283
        if ( $verbose == 1 ) {
281
        if ( $verbose == 1 ) {
284
            _log( 1, "$count records processed\n" ) if ( $count % 1000 == 0);
282
            _log( 1, "$count records processed\n" ) if ( $count % 1000 == 0);
Lines 287-293 sub _do_reindex { Link Here
287
        }
285
        }
288
286
289
        push @id_buffer,     $id;
287
        push @id_buffer,     $id;
290
        push @commit_buffer, $record_prepped;
288
        push @commit_buffer, $record;
291
        if ( !( --$commit_count ) ) {
289
        if ( !( --$commit_count ) ) {
292
            _log( 1, "Committing $commit records...\n" );
290
            _log( 1, "Committing $commit records...\n" );
293
            my $response = $indexer->update_index( \@id_buffer, \@commit_buffer );
291
            my $response = $indexer->update_index( \@id_buffer, \@commit_buffer );
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t (-14 / +4 lines)
Lines 340-349 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
340
        MARC::Field->new('999', '', '', c => '1234568'),
340
        MARC::Field->new('999', '', '', c => '1234568'),
341
        MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno),
341
        MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric', o => $long_callno),
342
    );
342
    );
343
    my $records = [
343
    my $records = [ $marc_record_1, $marc_record_2 ];
344
        { record => $marc_record_1 },
345
        { record => $marc_record_2 },
346
    ];
347
344
348
    $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
345
    $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
349
346
Lines 510-516 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' Link Here
510
        $large_marc_record->append_fields($item_field);
507
        $large_marc_record->append_fields($item_field);
511
    }
508
    }
512
509
513
    $docs = $see->marc_records_to_documents([{ record => $large_marc_record }]);
510
    $docs = $see->marc_records_to_documents([$large_marc_record]);
514
511
515
    is($docs->[0]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly');
512
    is($docs->[0]->{marc_format}, 'MARCXML', 'For record exceeding max record size marc_format should be set correctly');
516
513
Lines 623-632 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents_array () t Link Here
623
        MARC::Field->new('999', '', '', c => '1234568'),
620
        MARC::Field->new('999', '', '', c => '1234568'),
624
        MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric'),
621
        MARC::Field->new('952', '', '', 0 => 1, g => 'string where should be numeric'),
625
    );
622
    );
626
    my $records = [
623
    my $records = [ $marc_record_1, $marc_record_2 ];
627
        { record => $marc_record_1 },
628
        { record => $marc_record_2 },
629
    ];
630
624
631
    $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
625
    $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
632
626
Lines 701-710 subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () authori Link Here
701
    $marc_record_2->append_fields(
695
    $marc_record_2->append_fields(
702
        MARC::Field->new('150', '', '', a => 'Subject', v => 'Genresubdiv', z => 'Geosubdiv', x => 'Generalsubdiv', e => 'wrongsubdiv' ),
696
        MARC::Field->new('150', '', '', a => 'Subject', v => 'Genresubdiv', z => 'Geosubdiv', x => 'Generalsubdiv', e => 'wrongsubdiv' ),
703
    );
697
    );
704
    my $records = [
698
    my $records = [ $marc_record_1, $marc_record_2 ];
705
        { record => $marc_record_1, authtypecode=> $auth_type->authtypecode },
706
        { record => $marc_record_2, authtypecode=> $auth_type->authtypecode },
707
    ];
708
699
709
    $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
700
    $see->get_elasticsearch_mappings(); #sort_fields will call this and use the actual db values unless we call it first
710
701
711
- 

Return to bug 25273