From 6fe174d0676bb110de4fa4ad1c8d71ba0a277a78 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 26 Oct 2016 12:33:49 +0200 Subject: [PATCH] Bug 17500: Add a script to reindex patrons --- misc/search_tools/reindex_patrons.pl | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 misc/search_tools/reindex_patrons.pl diff --git a/misc/search_tools/reindex_patrons.pl b/misc/search_tools/reindex_patrons.pl new file mode 100644 index 0000000..ed581b7 --- /dev/null +++ b/misc/search_tools/reindex_patrons.pl @@ -0,0 +1,60 @@ +use Modern::Perl; + +use Koha::Patrons; +use Koha::SearchEngine::Elasticsearch; + +use Koha::SearchEngine::Elasticsearch::Indexer; + +my $index_name = "patrons"; +my $indexer = Koha::SearchEngine::Elasticsearch::Indexer->new( { index => $index_name } ); + +$indexer->drop_index; + +my $patrons = Koha::Patrons->search; + +my ( @id_buffer, @commit_buffer ); +while ( my $patron = $patrons->next ) { + my $id = $patron->borrowernumber; + my $record = $patron->unblessed; + $record->{_id} = $id; + push @id_buffer, $id; + push @commit_buffer, $record; +} + +warn "committing"; + +if ( !$indexer->store ) { + + my $params = $indexer->get_elasticsearch_params(); + my $mappings = { + data => { + properties => { + borrowernumber => { + type => 'string', + search_analyzer => 'analyser_standard', + index_analyzer => 'analyser_standard', + }, + cardnumber => { + type => 'string', + search_analyzer => 'analyser_standard', + index_analyzer => 'analyser_standard', + }, + surname => { + type => 'string', + search_analyzer => 'analyser_standard', + index_analyzer => 'analyser_standard', + }, + } + } + }; + $indexer->store( + Catmandu::Store::ElasticSearch->new( + %$params, + index_settings => $indexer->get_elasticsearch_settings(), + index_mappings => $mappings, + ) + ); +} + +$indexer->store->bag->add_many(\@commit_buffer); +$indexer->store->bag->commit; -- 2.1.4