1 package Koha::Indexer::Indexing;
8 use Koha::Indexer::RecordReader;
9 use Koha::Indexer::RecordWriter;
10 use AnyEvent::Processor::Conversion;
16 with 'MooseX::Getopt';
21 isa => 'Koha::RecordType',
27 isa => 'Koha::RecordSelect',
35 default => './koha-index',
38 has keep => ( is => 'rw', isa => 'Bool', default => 0 );
40 has verbose => ( is => 'rw', isa => 'Bool', default => 0 );
46 traits => [ 'NoGetopt' ],
53 traits => [ 'NoGetopt' ],
60 # Is it a full indexing of all Koha DB records?
61 my $is_full_indexing = $self->select =~ /all/i;
63 # Is it biblio indexing (if not it's authority)
64 my $is_biblio_indexing = $self->source =~ /biblio/i;
66 # STEP 1: All biblio records are exported in a directory
68 unless ( -d $self->directory ) {
69 mkdir $self->directory
70 or die "Unable to create directory: " . $self->directory;
72 my $from_dir = $self->directory . "/" . $self->source;
74 for my $dir ( ( "$from_dir/update", "$from_dir/delete") ) {
75 rmtree( $dir ) if -d $dir;
79 # DOM indexing? otherwise GRS-1
80 my $is_dom = $self->source eq 'biblio'
81 ? 'zebra_bib_index_mode'
82 : 'zebra_auth_index_mode';
83 $is_dom = C4::Context->config($is_dom) || '';
84 $is_dom = $is_dom =~ /dom/i ? 1 : 0;
86 # STEP 1.1: Records to update
87 say "Exporting records to update" if $self->verbose;
88 my $exporter = AnyEvent::Processor::Conversion->new(
89 reader => Koha::Indexer::RecordReader->new(
90 source => $self->source,
91 select => $is_full_indexing ? 'all' : 'queue_update',
94 writer => Koha::Indexer::RecordWriter->new(
95 fh => IO::File->new( "$from_dir/update/records", '>:encoding(utf8)' ),
97 blocking => $self->blocking,
98 verbose => $self->verbose,
102 # STEP 1.2: Record to delete, if zebraqueue
103 if ( ! $is_full_indexing ) {
104 say "Exporting records to delete" if $self->verbose;
105 $exporter = AnyEvent::Processor::Conversion->new(
106 reader => Koha::Indexer::RecordReader->new(
107 source => $self->source,
108 select => 'queue_delete',
111 writer => Koha::Indexer::RecordWriter->new(
112 fh => IO::File->new( "$from_dir/delete/records", '>:encoding(utf8)' ),
114 blocking => $self->blocking,
115 verbose => $self->verbose,
120 # STEP 2: Run zebraidx
123 my $zconfig = C4::Context->zebraconfig(
124 $is_biblio_indexing ? 'biblioserver' : 'authorityserver')->{config};
125 my $db_name = $is_biblio_indexing ? 'biblios' : 'authorities';
126 my $cmd_base = "zebraidx -c " . $zconfig;
127 $cmd_base .= " -n" if $is_full_indexing; # No shadow: no indexing daemon
128 $cmd_base .= $self->verbose ? " -v warning,log" : " -v none";
129 $cmd_base .= " -g marcxml";
130 $cmd_base .= " -d $db_name";
132 if ( $is_full_indexing ) {
133 $cmd = "$cmd_base init";
134 say $cmd if $self->verbose;
138 $cmd = "$cmd_base update $from_dir/update";
139 say $cmd if $self->verbose;
142 if ( ! $is_full_indexing ) {
143 $cmd = "$cmd_base adelete $from_dir/delete";
144 say $cmd if $self->verbose;
146 my $cmd = "$cmd_base commit";
147 say $cmd if $self->verbose;
151 rmtree( $self->directory ) unless $self->keep;
156 __PACKAGE__->meta->make_immutable;
163 my $indexer = Koha::Indexer->new(
169 my $indexer = Koha::Indexer->new(
170 source => 'authority',
179 Indexes Koha biblio/authority records, full indexing or queued record indexing.
188 Runs the indexing task.