-
Notifications
You must be signed in to change notification settings - Fork 62
/
rebuild_zebra.pl
executable file
·711 lines (621 loc) · 25.8 KB
/
rebuild_zebra.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
#!/usr/bin/perl
use strict;
use C4::Context;
use Getopt::Long;
use File::Temp qw/ tempdir /;
use File::Path;
use C4::Biblio;
use C4::Items;
use C4::AuthoritiesMarc;
use Unicode::Normalize;
use Business::ISBN;
#
# script that checks zebradir structure & create directories & mandatory files if needed
#
#
$|=1; # flushes output
my $directory;
my $nosanitize;
my $skip_export;
my $keep_export;
my $export_only;
my $reset;
my $biblios;
my $authorities;
my $noxml;
my $noshadow;
my $want_help;
my $as_xml;
my $process_zebraqueue;
my $do_not_clear_zebraqueue;
my $verbose_logging;
my $zebraidx_log_opt = " -v none,fatal,warn ";
my $result = GetOptions(
'd:s' => \$directory,
'r|reset' => \$reset,
's|skip' => \$skip_export,
'k|keep' => \$keep_export,
'e|export' => \$export_only,
'nosanitize' => \$nosanitize,
'b' => \$biblios,
'noxml' => \$noxml,
'w' => \$noshadow,
'a' => \$authorities,
'h|help' => \$want_help,
'x' => \$as_xml,
'y' => \$do_not_clear_zebraqueue,
'z' => \$process_zebraqueue,
'v' => \$verbose_logging,
);
if (not $result or $want_help) {
print_usage();
exit 0;
}
if (not $biblios and not $authorities) {
my $msg = "Must specify -b or -a to reindex bibs or authorities\n";
$msg .= "Please do '$0 --help' to see usage.\n";
die $msg;
}
if ($skip_export and $export_only) {
my $msg = "Cannot specify both 'skip export' and 'export only'\n";
$msg .= "Please do '$0 --help' to see usage.\n";
die $msg;
}
if ( ! $keep_export and $export_only) {
my $msg = "There's really no point in 'export only' if the export is immediately deleted. You probably want -k if you use -e.\n";
$msg .= "Please do '$0 --help' to see usage.\n";
die $msg;
}
if ($authorities and $as_xml and not $biblios) {
my $msg = "Cannot specify both -a and -x\n";
$msg .= "Please do '$0 --help' to see usage.\n";
die $msg;
}
if ( !$as_xml and $nosanitize ) {
my $msg = "Cannot specify both -no_xml and -nosanitize\n";
$msg .= "Please do '$0 --help' to see usage.\n";
die $msg;
}
if ($process_zebraqueue and ($skip_export or $reset)) {
my $msg = "Cannot specify -r or -s if -z is specified\n";
$msg .= "Please do '$0 --help' to see usage.\n";
die $msg;
}
if ($process_zebraqueue and $do_not_clear_zebraqueue) {
my $msg = "Cannot specify both -y and -z\n";
$msg .= "Please do '$0 --help' to see usage.\n";
die $msg;
}
if ($noshadow) {
$noshadow = ' -n ';
}
# -v is for verbose, which seems backwards here because of how logging is set
# on the CLI of zebraidx. It works this way. The default is to not log much
if ($verbose_logging) {
$zebraidx_log_opt = '';
}
my $use_tempdir = 0;
unless ($directory) {
$use_tempdir = 1;
$directory = tempdir(CLEANUP => ($keep_export ? 0 : 1));
}
my $biblioserverdir = C4::Context->zebraconfig('biblioserver')->{directory};
my $authorityserverdir = C4::Context->zebraconfig('authorityserver')->{directory};
my $kohadir = C4::Context->config('intranetdir');
my $dbh = C4::Context->dbh;
my ($biblionumbertagfield,$biblionumbertagsubfield) = &GetMarcFromKohaField("biblio.biblionumber","");
my ($biblioitemnumbertagfield,$biblioitemnumbertagsubfield) = &GetMarcFromKohaField("biblioitems.biblioitemnumber","");
if ( $verbose_logging ) {
print "Zebra configuration information\n";
print "================================\n";
print "Zebra biblio directory = $biblioserverdir\n";
print "Zebra authorities directory = $authorityserverdir\n";
print "Koha directory = $kohadir\n";
print "BIBLIONUMBER in : $biblionumbertagfield\$$biblionumbertagsubfield\n";
print "BIBLIOITEMNUMBER in : $biblioitemnumbertagfield\$$biblioitemnumbertagsubfield\n";
print "================================\n";
}
if ($authorities) {
# undef $as_xml to allow -x and -a to be specified when -b is also specified.
index_records('authority', $directory, $skip_export, $process_zebraqueue, undef , $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt);
} else {
print "skipping authorities\n" if ( $verbose_logging );
}
if ($biblios) {
index_records('biblio', $directory, $skip_export, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt);
} else {
print "skipping biblios\n" if ( $verbose_logging );
}
if ( $verbose_logging ) {
print "====================\n";
print "CLEANING\n";
print "====================\n";
}
if ($keep_export) {
print "NOTHING cleaned : the export $directory has been kept.\n";
print "You can re-run this script with the -s ";
if ($use_tempdir) {
print " and -d $directory parameters";
} else {
print "parameter";
}
print "\n";
print "if you just want to rebuild zebra after changing the record.abs\n";
print "or another zebra config file\n";
} else {
unless ($use_tempdir) {
# if we're using a temporary directory
# created by File::Temp, it will be removed
# automatically.
rmtree($directory, 0, 1);
print "directory $directory deleted\n";
}
}
sub index_records {
my ($record_type, $directory, $skip_export, $process_zebraqueue, $as_xml, $noxml, $nosanitize, $do_not_clear_zebraqueue, $verbose_logging, $zebraidx_log_opt) = @_;
my $num_records_exported = 0;
my $num_records_deleted = 0;
my $deleted_entries;
my $soft_deleted_entries;
my $updated_entries;
if ($skip_export && $verbose_logging) {
print "====================\n";
print "SKIPPING $record_type export\n";
print "====================\n";
} else {
if ( $verbose_logging ) {
print "====================\n";
print "exporting $record_type\n";
print "====================\n";
}
mkdir "$directory" unless (-d $directory);
mkdir "$directory/$record_type" unless (-d "$directory/$record_type");
if ($process_zebraqueue) {
mkdir "$directory/del_$record_type" unless (-d "$directory/del_$record_type");
($verbose_logging) and print "Generating deleted records...\n";
$deleted_entries = select_zebraqueue_records($record_type, 'deleted');
$num_records_deleted = generate_deleted_marc_records($record_type, $deleted_entries, "$directory/del_$record_type", $as_xml);
mkdir "$directory/upd_$record_type" unless (-d "$directory/upd_$record_type");
($verbose_logging) and print "Selecting soft-deleted records...\n";
$soft_deleted_entries = select_zebraqueue_records($record_type, 'soft_deleted');
$num_records_exported = export_marc_records_from_list($record_type, $soft_deleted_entries, "$directory/upd_$record_type", $as_xml, $noxml, 'soft_deleted');
($verbose_logging) and print "Selecting updated records...\n";
$updated_entries = select_zebraqueue_records($record_type, 'updated');
$num_records_exported += export_marc_records_from_list($record_type, $updated_entries, "$directory/upd_$record_type", $as_xml, $noxml);
} else {
my $sth = select_all_records($record_type);
$num_records_exported = export_marc_records_from_sth($record_type, $sth, "$directory/$record_type", $as_xml, $noxml, $nosanitize);
if ($record_type eq 'biblio') {
$sth = select_all_records($record_type, 'soft_deleted');
$num_records_exported += export_marc_records_from_sth($record_type, $sth, "$directory/$record_type", $as_xml, $noxml, $nosanitize, 'soft_deleted');
}
unless ($do_not_clear_zebraqueue) {
mark_all_zebraqueue_done($record_type);
}
}
}
#
# and reindexing everything
#
unless( $export_only ){
if ( $verbose_logging ) {
print "====================\n";
print "REINDEXING zebra\n";
print "====================\n";
}
my $record_fmt = ($as_xml) ? 'marcxml' : 'iso2709' ;
if ($process_zebraqueue) {
if ($num_records_deleted){
do_indexing($record_type, 'delete', "$directory/del_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt);
mark_zebraqueue_batch_done($deleted_entries);
}
if ($num_records_exported){
do_indexing($record_type, 'update', "$directory/upd_$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt);
mark_zebraqueue_batch_done($soft_deleted_entries);
mark_zebraqueue_batch_done($updated_entries);
}
} else {
do_indexing($record_type, 'update', "$directory/$record_type", $reset, $noshadow, $record_fmt, $zebraidx_log_opt)
if ($num_records_exported or $skip_export);
}
}
}
sub select_zebraqueue_records {
my ($record_type, $update_type) = @_;
my %op_for = (
deleted => 'recordDelete',
updated => 'specialUpdate',
soft_deleted => 'softDelete',
);
my $server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
my $op = $op_for{$update_type};
my $sth = $dbh->prepare("SELECT id, biblio_auth_number
FROM zebraqueue
WHERE server = ?
AND operation = ?
AND done = 0
ORDER BY id DESC");
$sth->execute($server, $op);
my $entries = $sth->fetchall_arrayref({});
}
sub mark_all_zebraqueue_done {
my ($record_type) = @_;
my $server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
my $sth = $dbh->prepare("UPDATE zebraqueue SET done = 1
WHERE server = ?
AND done = 0");
$sth->execute($server);
}
sub mark_zebraqueue_batch_done {
my ($entries) = @_;
$dbh->{AutoCommit} = 0;
my $sth = $dbh->prepare("UPDATE zebraqueue SET done = 1 WHERE id = ?");
$dbh->commit();
foreach my $id (map { $_->{id} } @$entries) {
$sth->execute($id);
}
$dbh->{AutoCommit} = 1;
}
sub select_all_records {
my $record_type = shift;
my $soft_deleted = shift;
return ($record_type eq 'biblio') ? select_all_biblios($soft_deleted) : select_all_authorities();
}
sub select_all_authorities {
my $sth = $dbh->prepare("SELECT authid FROM auth_header");
$sth->execute();
return $sth;
}
sub select_all_biblios {
my $soft_deleted = shift;
my $biblioitems = "biblioitems";
if ($soft_deleted) {
$biblioitems = "deletedbiblioitems";
}
my $sth = $dbh->prepare("SELECT biblionumber FROM $biblioitems ORDER BY biblionumber");
$sth->execute();
return $sth;
}
sub export_marc_records_from_sth {
my ($record_type, $sth, $directory, $as_xml, $noxml, $nosanitize, $soft_deleted) = @_;
my $num_exported = 0;
my $mode = (-e "$directory/exported_records")
? ">>:utf8"
: ">:utf8";
open (OUT, $mode, "$directory/exported_records") or die $!;
my $i = 0;
EXPORT_RECORD:
while (my ($record_number) = $sth->fetchrow_array) {
print "." if ( $verbose_logging );
print "$i\r" unless ($i++ %100 or !$verbose_logging);
if ( $nosanitize ) {
my $marcxml = $record_type eq 'biblio'
? GetXmlBiblio( $record_number )
: GetAuthorityXML( $record_number );
if ( $marcxml ) {
print OUT $marcxml if $marcxml;
$num_exported++;
}
next;
}
my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml, $soft_deleted);
if (defined $marc) {
# FIXME - when more than one record is exported and $as_xml is true,
# the output file is not valid XML - it's just multiple <record> elements
# strung together with no single root element. zebraidx doesn't seem
# to care, though, at least if you're using the GRS-1 filter. It does
# care if you're using the DOM filter, which requires valid XML file(s).
# Also, encoding problems with the record can cause as_xml_record() to fail
# even if the MARC::Record object was successfully created, so we add an eval.
if($as_xml){
my $marcxml;
eval { $marcxml = $marc->as_xml_record(); };
if ($@) {
warn "Failure in MARC::File::XML. Skipping record";
next EXPORT_RECORD;
}
print OUT NFC($marc->as_xml_record());
} else {
print OUT $marc->as_usmarc();
}
$num_exported++;
}
}
print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
close OUT;
return $num_exported;
}
sub export_marc_records_from_list {
my ($record_type, $entries, $directory, $as_xml, $noxml, $soft_deleted) = @_;
my $num_exported = 0;
my $mode = (-e "$directory/exported_records")
? ">>:utf8"
: ">:utf8";
open (OUT, $mode, "$directory/exported_records") or die $!;
my $i = 0;
my %found = ();
foreach my $record_number ( map { $_->{biblio_auth_number} }
grep { !$found{ $_->{biblio_auth_number} }++ }
@$entries ) {
print "." if ( $verbose_logging );
print "\r$i" unless ($i++ %100 or !$verbose_logging);
my ($marc) = get_corrected_marc_record($record_type, $record_number, $noxml, $soft_deleted);
if (defined $marc) {
# FIXME - when more than one record is exported and $as_xml is true,
# the output file is not valid XML - it's just multiple <record> elements
# strung together with no single root element. zebraidx doesn't seem
# to care, though, at least if you're using the GRS-1 filter. It does
# care if you're using the DOM filter, which requires valid XML file(s).
# print OUT ($as_xml) ? NFC($marc->as_xml_record()) : $marc->as_usmarc();
if($as_xml){
my $marcxml;
eval { $marcxml = $marc->as_xml_record(); };
if ($@) {
warn "Failure in MARC::File::XML. Skipping record";
next;
}
print OUT NFC($marc->as_xml_record());
} else {
print OUT $marc->as_usmarc();
}
$num_exported++;
}
}
print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
close OUT;
return $num_exported;
}
sub generate_deleted_marc_records {
my ($record_type, $entries, $directory, $as_xml) = @_;
my $num_exported = 0;
open (OUT, ">:utf8 ", "$directory/exported_records") or die $!;
my $i = 0;
foreach my $record_number (map { $_->{biblio_auth_number} } @$entries ) {
print "\r$i" unless ($i++ %100 or !$verbose_logging);
print "." if ( $verbose_logging );
my $marc = MARC::Record->new();
if ($record_type eq 'biblio') {
fix_biblio_ids($marc, $record_number, $record_number);
} else {
fix_authority_id($marc, $record_number);
}
if (C4::Context->preference("marcflavour") eq "UNIMARC") {
fix_unimarc_100($marc);
}
print OUT ($as_xml) ? NFC($marc->as_xml_record()) : $marc->as_usmarc();
$num_exported++;
}
print "\nRecords exported: $num_exported\n" if ( $verbose_logging );
close OUT;
return $num_exported;
}
sub get_corrected_marc_record {
my ($record_type, $record_number, $noxml, $soft_deleted) = @_;
my $marc = get_raw_marc_record($record_type, $record_number, $noxml, $soft_deleted);
if (defined $marc) {
fix_leader($marc);
if ($record_type eq 'biblio') {
my $succeeded = fix_biblio_ids($marc, $record_number, $soft_deleted);
return unless $succeeded;
add_isbn13s($marc);
} else {
fix_authority_id($marc, $record_number);
}
if (C4::Context->preference("marcflavour") eq "UNIMARC") {
fix_unimarc_100($marc);
}
}
return $marc;
}
sub get_raw_marc_record {
my ($record_type, $record_number, $noxml, $soft_deleted) = @_;
my $marc;
if ($record_type eq 'biblio') {
if ($noxml) {
my $table = ($soft_deleted) ? "deletedbiblioitems" : "biblioitems";
my $fetch_sth = $dbh->prepare_cached("SELECT marc FROM $table WHERE biblionumber = ?");
$fetch_sth->execute($record_number);
if (my ($blob) = $fetch_sth->fetchrow_array) {
$marc = MARC::Record->new_from_usmarc($blob);
$fetch_sth->finish();
} else {
return; # failure to find a bib is not a problem -
# a delete could have been done before
# trying to process a record update
}
} else {
my $marc_sans_items;
eval { $marc_sans_items = GetMarcBiblio($record_number, $soft_deleted); };
if ($@) {
# here we do warn since catching an exception
# means that the bib was found but failed
# to be parsed
warn "error retrieving biblio $record_number : $@";
return;
}
$marc = GetMarcWithItems($record_number, $marc_sans_items);
}
} else {
eval { $marc = GetAuthority($record_number); };
if ($@) {
warn "error retrieving authority $record_number";
return;
}
}
return $marc;
}
sub fix_leader {
# FIXME - this routine is suspect
# It blanks the Leader/00-05 and Leader/12-16 to
# force them to be recalculated correct when
# the $marc->as_usmarc() or $marc->as_xml() is called.
# But why is this necessary? It would be a serious bug
# in MARC::Record (definitely) and MARC::File::XML (arguably)
# if they are emitting incorrect leader values.
my $marc = shift;
my $leader = $marc->leader;
substr($leader, 0, 5) = ' ';
substr($leader, 10, 7) = '22 ';
$marc->leader(substr($leader, 0, 24));
}
sub fix_biblio_ids {
# FIXME - it is essential to ensure that the biblionumber is present,
# otherwise, Zebra will choke on the record. However, this
# logic belongs in the relevant C4::Biblio APIs.
my $marc = shift;
my $biblionumber = shift;
my $soft_deleted = shift;
my $biblioitemnumber;
if (@_) {
$biblioitemnumber = shift;
} else {
my $table = $soft_deleted
? "deletedbiblioitems"
: "biblioitems";
my $sth = $dbh->prepare(
"SELECT biblioitemnumber FROM $table WHERE biblionumber=?");
$sth->execute($biblionumber);
($biblioitemnumber) = $sth->fetchrow_array;
$sth->finish;
unless ($biblioitemnumber) {
warn "failed to get biblioitemnumber for biblio $biblionumber";
return 0;
}
}
# FIXME - this is cheating on two levels
# 1. C4::Biblio::_koha_marc_update_bib_ids is meant to be an internal function
# 2. Making sure that the biblionumber and biblioitemnumber are correct and
# present in the MARC::Record object ought to be part of GetMarcBiblio.
#
# On the other hand, this better for now than what rebuild_zebra.pl used to
# do, which was duplicate the code for inserting the biblionumber
# and biblioitemnumber
C4::Biblio::_koha_marc_update_bib_ids($marc, '', $biblionumber, $biblioitemnumber);
return 1;
}
sub add_isbn13s {
my $marc = shift;
my ($isbntag, $isbnsubfield) = GetMarcFromKohaField('biblioitems.isbn', '');
return unless $isbntag and $isbnsubfield;
my %isbns =();
foreach my $field ($marc->field($isbntag)) {
my $sfa = $field->subfield('a');
next unless $sfa;
my ($isbn_str) = $sfa =~ /^([0-9-]+[0-9xX])/;
next unless defined $isbn_str;
$isbn_str =~ s/-//;
$isbns{$isbn_str}++;
my $isbn = Business::ISBN->new($isbn_str);
next unless defined $isbn;
next unless $isbn->is_valid();
my $isbn13_str = $isbn->as_isbn13()->as_string([]);
$isbns{$isbn13_str}++;
my $isbn10 = $isbn->as_isbn10();
next unless defined $isbn10;
$isbns{$isbn10->as_string([])}++;
}
return unless %isbns;
if (my $f999 = $marc->field('999')) {
$f999->add_subfields(map { ('e' => $_) } keys %isbns);
} else {
$marc->append_field(MARC::Field->new('999', ' ', ' ', map { ('e' => $_) } keys %isbns));
}
}
sub fix_authority_id {
# FIXME - as with fix_biblio_ids, the authid must be present
# for Zebra's sake. However, this really belongs
# in C4::AuthoritiesMarc.
my ($marc, $authid) = @_;
unless ($marc->field('001') and $marc->field('001')->data() eq $authid){
$marc->delete_field($marc->field('001'));
$marc->insert_fields_ordered(MARC::Field->new('001',$authid));
}
}
sub fix_unimarc_100 {
# FIXME - again, if this is necessary, it belongs in C4::AuthoritiesMarc.
my $marc = shift;
my $string;
if ( length($marc->subfield( 100, "a" )) == 35 ) {
$string = $marc->subfield( 100, "a" );
my $f100 = $marc->field(100);
$marc->delete_field($f100);
}
else {
$string = POSIX::strftime( "%Y%m%d", localtime );
$string =~ s/\-//g;
$string = sprintf( "%-*s", 35, $string );
}
substr( $string, 22, 6, "frey50" );
unless ( length($marc->subfield( 100, "a" )) == 35 ) {
$marc->delete_field($marc->field(100));
$marc->insert_grouped_field(MARC::Field->new( 100, "", "", "a" => $string ));
}
}
sub do_indexing {
my ($record_type, $op, $record_dir, $reset_index, $noshadow, $record_format, $zebraidx_log_opt) = @_;
my $zebra_server = ($record_type eq 'biblio') ? 'biblioserver' : 'authorityserver';
my $zebra_db_name = ($record_type eq 'biblio') ? 'biblios' : 'authorities';
my $zebra_config = C4::Context->zebraconfig($zebra_server)->{'config'};
my $zebra_db_dir = C4::Context->zebraconfig($zebra_server)->{'directory'};
if ($reset_index) {
system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name init") == 0
or die("$!");
}
system("zebraidx -c $zebra_config $zebraidx_log_opt $noshadow -g $record_format -d $zebra_db_name $op $record_dir") == 0
or die("$!");
unless ($noshadow) {
system("zebraidx -c $zebra_config $zebraidx_log_opt -g $record_format -d $zebra_db_name commit") == 0
or die("$!");
}
}
sub print_usage {
print <<_USAGE_;
$0: reindex MARC bibs and/or authorities in Zebra.
Use this batch job to reindex all biblio or authority
records in your Koha database. This job is useful
only if you are using Zebra; if you are using the 'NoZebra'
mode, this job should not be used.
Parameters:
-b index bibliographic records
-a index authority records
-z select only updated and deleted
records marked in the zebraqueue
table. Cannot be used with -r
or -s.
-r, --reset Clear Zebra index before
adding records to index
-d Temporary directory for indexing.
If not specified, one is automatically
created. The export directory
is automatically deleted unless
you supply the -k switch.
-k, --keep Do not delete export directory.
-s, --skip Skip export. Used if you have
already exported the records
in a previous run.
-noxml index from ISO MARC blob
instead of MARC XML. This
option is recommended only
for advanced user.
-x export and index as xml instead of is02709 (biblios only).
use this if you might have records > 99,999 chars,
or if you want your records converted to NFC for better search results on export.
This option is ignored for authorities if both -b and -a are specified.
-nosanitize export biblio/authority records directly from DB marcxml
field without sanitizing records. It speeds up
dump process but could fail if DB contains badly
encoded records. Works only with -x. WARNING: Item data will not be indexed with this option.
-w skip shadow indexing for this batch
-y do NOT clear zebraqueue after indexing; normally,
after doing batch indexing, zebraqueue should be
marked done for the affected record type(s) so that
a running zebraqueue_daemon doesn't try to reindex
the same records - specify -y to override this.
Cannot be used with -z.
-v increase the amount of logging. Normally only
warnings and errors from the indexing are shown.
-e, --export do not index records, just export for indexing.
This option requires -k. option -r is ignored if -e is specified.
--help or -h show this message.
_USAGE_
}