From 73dfdcbca743b31899beadaccfa27fe0a8cb1d1e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 16 Feb 2017 10:22:27 +0000 Subject: [PATCH] Bug 18130: ES - Fix --biblionumbers for rebuild elastic indexes rebuild_elastic_search.pl provides a --biblionumber/-bn option to reindex only given biblionumbers. However it does not work and the script explodes with Can't locate object method "id" via package "MARC::Record" Test plan: Full reindex and reindex only given biblionumbers should work: perl misc/search_tools/rebuild_elastic_search.pl -a -b -v perl misc/search_tools/rebuild_elastic_search.pl -b -v perl misc/search_tools/rebuild_elastic_search.pl -b -bn 42 -v --- Koha/BiblioUtils.pm | 14 +++++++++--- Koha/MetadataRecord/Authority.pm | 11 +++++++--- misc/search_tools/rebuild_elastic_search.pl | 33 +++++++---------------------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/Koha/BiblioUtils.pm b/Koha/BiblioUtils.pm index abb0721..5ec881d 100644 --- a/Koha/BiblioUtils.pm +++ b/Koha/BiblioUtils.pm @@ -111,11 +111,19 @@ The iterator is a Koha::MetadataIterator object. =cut sub get_all_biblios_iterator { + my ( @biblionumbers ) = @_; my $database = Koha::Database->new(); my $schema = $database->schema(); - my $rs = - $schema->resultset('Biblio')->search( {}, - { columns => [qw/ biblionumber /] } ); + my $rs = $schema->resultset('Biblio')->search( + { + ( + @biblionumbers + ? ( biblionumber => { -in => \@biblionumbers } ) + : () + ) + }, + { columns => [qw/ biblionumber /] } + ); my $next_func = sub { # Warn and skip bad records, otherwise we break the loop while (1) { diff --git a/Koha/MetadataRecord/Authority.pm b/Koha/MetadataRecord/Authority.pm index c3b3314..3468af2 100644 --- a/Koha/MetadataRecord/Authority.pm +++ b/Koha/MetadataRecord/Authority.pm @@ -167,11 +167,16 @@ The iterator is a Koha::MetadataIterator object. =cut sub get_all_authorities_iterator { + my ( @authid ) = @_; my $database = Koha::Database->new(); my $schema = $database->schema(); - my $rs = - $schema->resultset('AuthHeader')->search( { marcxml => { '!=', undef } }, - { columns => [qw/ authid authtypecode marcxml /] } ); + my $rs = $schema->resultset('AuthHeader')->search( + { + marcxml => { '!=', undef }, + ( @authid ? ( authid => { -in => \@authid } ) : () ) + }, + { columns => [qw/ authid authtypecode marcxml /] } + ); my $next_func = sub { my $row = $rs->next(); return if !$row; diff --git a/misc/search_tools/rebuild_elastic_search.pl b/misc/search_tools/rebuild_elastic_search.pl index 6faa32c..7666660 100755 --- a/misc/search_tools/rebuild_elastic_search.pl +++ b/misc/search_tools/rebuild_elastic_search.pl @@ -124,35 +124,18 @@ sanity_check(); my $next; if ($index_biblios) { _log(1, "Indexing biblios\n"); - if (@biblionumbers) { - $next = sub { - my $r = shift @biblionumbers; - return () unless defined $r; - return ($r, Koha::BiblioUtils->get_from_biblionumber($r, item_data => 1 )); - }; - } else { - my $records = Koha::BiblioUtils->get_all_biblios_iterator(); - $next = sub { - $records->next(); - } - } + my $records = Koha::BiblioUtils->get_all_biblios_iterator( @biblionumbers ); + $next = sub { + $records->next(); + }; do_reindex($next, $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX); } if ($index_authorities) { _log(1, "Indexing authorities\n"); - if (@biblionumbers) { - $next = sub { - my $r = shift @biblionumbers; - return () unless defined $r; - my $a = Koha::MetadataRecord::Authority->get_from_authid($r); - return ($r, $a->record); - }; - } else { - my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator(); - $next = sub { - $records->next(); - } - } + my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator( @biblionumbers ); + $next = sub { + $records->next(); + }; do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); } -- 2.1.4