@@ -, +, @@ given date the columns specified above) biblio_metadata ORDER BY timestamp) $DATE can be a date (YYYY-MM-DD) or datetime (YYYY-MM-DD HH:MM[:SS]) manually the columns specified above) auth_header ORDER BY modification_time) $DATE can be a date (YYYY-MM-DD) or datetime (YYYY-MM-DD HH:MM[:SS]) --- Koha/BiblioUtils.pm | 14 ++++++++++---- Koha/MetadataRecord/Authority.pm | 20 +++++++++----------- misc/search_tools/rebuild_elasticsearch.pl | 12 ++++++++++++ 3 files changed, 31 insertions(+), 15 deletions(-) --- a/Koha/BiblioUtils.pm +++ a/Koha/BiblioUtils.pm @@ -125,15 +125,21 @@ records instead of all. sub get_all_biblios_iterator { my ($self, %options) = @_; - my $search_terms = {}; + my @search_terms; + my $search_options = { columns => [qw/ biblionumber /] }; + my ($slice_modulo, $slice_count); if ($options{slice}) { $slice_count = $options{slice}->{count}; $slice_modulo = $options{slice}->{index}; - $search_terms = \[ 'mod(biblionumber, ?) = ?', $slice_count, $slice_modulo ]; + push @search_terms, \[ 'mod(biblionumber, ?) = ?', $slice_count, $slice_modulo ]; + } + + if ($options{modified_since}) { + $search_options->{join} = 'biblio_metadatas'; + push @search_terms, { 'biblio_metadatas.timestamp' => { '>=', $options{modified_since} } }; } - my $search_options = { columns => [qw/ biblionumber /] }; if ( $options{desc} ){ $search_options->{order_by} = { -desc => 'biblionumber' }; } @@ -142,7 +148,7 @@ sub get_all_biblios_iterator { my $schema = $database->schema(); my $rs = $schema->resultset('Biblio')->search( - $search_terms, + [ -and => \@search_terms ], $search_options ); my $next_func = sub { # Warn and skip bad records, otherwise we break the loop --- a/Koha/MetadataRecord/Authority.pm +++ a/Koha/MetadataRecord/Authority.pm @@ -175,22 +175,20 @@ records instead of all. sub get_all_authorities_iterator { my ($self, %options) = @_; - my $search_terms = { - marcxml => { '!=', undef } - }; + my @search_terms = ( { marcxml => { '!=', undef } } ); + my $search_options->{columns} = [qw/ authid /]; + my ($slice_modulo, $slice_count); if ($options{slice}) { $slice_count = $options{slice}->{count}; $slice_modulo = $options{slice}->{index}; - $search_terms = { - '-and' => [ - %{$search_terms}, - \[ 'mod(authid, ?) = ?', $slice_count, $slice_modulo ] - ] - }; + push @search_terms, \[ 'mod(authid, ?) = ?', $slice_count, $slice_modulo ]; + } + + if ($options{modified_since}) { + push @search_terms, { 'modification_time' => { '>=', $options{modified_since} } }; } - my $search_options->{columns} = [qw/ authid /]; if ($options{desc}) { $search_options->{order_by} = { -desc => 'authid' }; } @@ -199,7 +197,7 @@ sub get_all_authorities_iterator { my $schema = $database->schema(); my $rs = $schema->resultset('AuthHeader')->search( - $search_terms, + [ -and => \@search_terms ], $search_options); my $next_func = sub { # Warn and skip bad records, otherwise we break the loop --- a/misc/search_tools/rebuild_elasticsearch.pl +++ a/misc/search_tools/rebuild_elasticsearch.pl @@ -34,6 +34,7 @@ B [B<--desc>] [B<-bn|--bnumber>] [B<-ai|--authid>] +[B<--modified-since=DATETIME>] [B<-p|--processes>] [B<-v|--verbose>] [B<-h|--help>] @@ -87,6 +88,11 @@ repeated. Only index the supplied authority id, mostly for testing purposes. May be repeated. +=item B<--modified-since=DATETIME> + +Only index records modified since supplied datetime. It cannot be used with +--bnumber or --authid options. + =item B<-p|--processes> Number of processes to use for indexing. This can be used to do more indexing @@ -128,6 +134,7 @@ my $verbose = 0; my $commit = 5000; my ($delete, $reset, $help, $man, $processes); my ($index_biblios, $index_authorities); +my $modified_since; my (@biblionumbers,@authids); my $desc; @@ -142,6 +149,7 @@ GetOptions( 'desc' => \$desc, 'bn|bnumber=i' => \@biblionumbers, 'ai|authid=i' => \@authids, + 'modified-since=s' => \$modified_since, 'p|processes=i' => \$processes, 'v|verbose+' => \$verbose, 'h|help' => \$help, @@ -193,6 +201,10 @@ if ($slice_count > 1) { $iterator_options{slice} = { index => $slice_index, count => $slice_count }; } +if ($modified_since) { + $iterator_options{modified_since} = $modified_since; +} + if( $desc ){ $iterator_options{desc} = 1; } --