From c3e6bad59e7032fe587dc4ed190d28156aed18cd Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 2 May 2019 10:21:36 +0000 Subject: [PATCH] Bug 22826: Allow indexing of individual authorities in Elasticsearch To test: 1 - perl misc/search_tools/rebuild_elastic_search.pl -h 2 - Note it indicates the bn option can be passed to index individual authids 3 - perl misc/search_tools/rebuild_elastic_search.pl -a -bn 92 -v 4 - Note the error 5 - Apply patch 6 - perl misc/search_tools/rebuild_elastic_search.pl -h 7 - Note new option ai|authid for indexing individual authids 8 - Note updated text for bn|biblionumber option 9 - perl misc/search_tools/rebuild_elastic_search.pl -a -bn 92 -v 10 - No errors, but no records indexed 11 - perl misc/search_tools/rebuild_elastic_search.pl -a -ai 92 -v 12 - 1 record indexed 13 - perl misc/search_tools/rebuild_elastic_search.pl -ai 92 -bn 92 -v 14 - 1 authority record and 1 biblio record indexed --- misc/search_tools/rebuild_elastic_search.pl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/misc/search_tools/rebuild_elastic_search.pl b/misc/search_tools/rebuild_elastic_search.pl index a233cf5d0f..54e458ff13 100755 --- a/misc/search_tools/rebuild_elastic_search.pl +++ b/misc/search_tools/rebuild_elastic_search.pl @@ -61,8 +61,12 @@ specifying neither and so both get indexed. =item B<-bn|--bnumber> Only index the supplied biblionumber, mostly for testing purposes. May be -repeated. This also applies to authorities via authid, so if you're using it, -you probably only want to do one or the other at a time. +repeated. + +=item B<-ai|--authid> + +Only index the supplied authority id, mostly for testing purposes. May be +repeated. =item B<-v|--verbose> @@ -97,7 +101,7 @@ my $verbose = 0; my $commit = 5000; my ($delete, $help, $man); my ($index_biblios, $index_authorities); -my (@biblionumbers); +my (@biblionumbers,@authids); $|=1; # flushes output @@ -107,6 +111,7 @@ GetOptions( 'a|authorities' => \$index_authorities, 'b|biblios' => \$index_biblios, 'bn|bnumber=i' => \@biblionumbers, + 'ai|authid=i' => \@authids, 'v|verbose+' => \$verbose, 'h|help' => \$help, 'man' => \$man, @@ -141,12 +146,12 @@ if ($index_biblios) { } if ($index_authorities) { _log(1, "Indexing authorities\n"); - if (@biblionumbers) { + if (@authids) { $next = sub { - my $r = shift @biblionumbers; + my $r = shift @authids; return () unless defined $r; my $a = Koha::MetadataRecord::Authority->get_from_authid($r); - return ($r, $a->record); + return ($r, $a); }; } else { my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator(); @@ -180,7 +185,7 @@ sub do_reindex { my $commit_count = $commit; my ( @id_buffer, @commit_buffer ); while ( my $record = $next->() ) { - my $id = $record->id; + my $id = $record->id // $record->authid; my $record = $record->record; $count++; if ( $verbose == 1 ) { -- 2.11.0