|
Lines 31-36
B<rebuild_elastic_search.pl>
Link Here
|
| 31 |
[B<-d|--delete>] |
31 |
[B<-d|--delete>] |
| 32 |
[B<-a|--authorities>] |
32 |
[B<-a|--authorities>] |
| 33 |
[B<-b|--biblios>] |
33 |
[B<-b|--biblios>] |
|
|
34 |
[B<-f|--file>] |
| 34 |
[B<-bn|--bnnumber>] |
35 |
[B<-bn|--bnnumber>] |
| 35 |
[B<--length>] |
36 |
[B<--length>] |
| 36 |
[B<--offset>] |
37 |
[B<--offset>] |
|
Lines 64-84
specifying neither and so both get indexed.
Link Here
|
| 64 |
Index the biblios only. Combining this with B<-a> is the same as |
65 |
Index the biblios only. Combining this with B<-a> is the same as |
| 65 |
specifying neither and so both get indexed. |
66 |
specifying neither and so both get indexed. |
| 66 |
|
67 |
|
|
|
68 |
=item B<-f|--file> |
| 69 |
|
| 70 |
Read a csv file created with a sql query, the csv must contain a column of biblionumber from biblios |
| 71 |
or a column of authid from auth_header, then index biblios or authorities, but not both. |
| 72 |
With this option you can't have options B<--length>, B<--offset>, and B<-bn>. |
| 73 |
|
| 67 |
=item B<-bn|--bnumber> |
74 |
=item B<-bn|--bnumber> |
| 68 |
|
75 |
|
| 69 |
Only index the supplied biblionumber, mostly for testing purposes. May be |
76 |
Only index the supplied biblionumber, mostly for testing purposes. May be |
| 70 |
repeated. This also applies to authorities via authid, so if you're using it, |
77 |
repeated. This also applies to authorities via authid, so if you're using it, |
| 71 |
you probably only want to do one or the other at a time. |
78 |
you probably only want to do one or the other at a time, |
|
|
79 |
with this option you can't have options B<--offset> and B<--length>. |
| 72 |
|
80 |
|
| 73 |
=item B<--offset> |
81 |
=item B<--offset> |
| 74 |
|
82 |
|
| 75 |
Specify the row number for the first row to be indexed. |
83 |
Specify the row number for the first row to be indexed. |
| 76 |
With this option you have to choose between biblios (-b) or authorities (-a). |
84 |
With this option you have to choose between biblios B<-b> or authorities B<-a>. |
| 77 |
|
85 |
|
| 78 |
=item B<--length> |
86 |
=item B<--length> |
| 79 |
|
87 |
|
| 80 |
Specify the number of rows to be indexed. |
88 |
Specify the number of rows to be indexed. |
| 81 |
With this option you have to choose between biblios (-b) or authorities (-a). |
89 |
With this option you have to choose between biblios B<-b> or authorities B<-a>. |
| 82 |
|
90 |
|
| 83 |
=item B<-v|--verbose> |
91 |
=item B<-v|--verbose> |
| 84 |
|
92 |
|
|
Lines 108-120
use MARC::Field;
Link Here
|
| 108 |
use MARC::Record; |
116 |
use MARC::Record; |
| 109 |
use Modern::Perl; |
117 |
use Modern::Perl; |
| 110 |
use Pod::Usage; |
118 |
use Pod::Usage; |
|
|
119 |
use Text::CSV; |
| 111 |
|
120 |
|
| 112 |
my $verbose = 0; |
121 |
my $verbose = 0; |
| 113 |
my $commit = 5000; |
122 |
my $commit = 5000; |
| 114 |
my ($delete, $help, $man); |
123 |
my ($delete, $help, $man); |
| 115 |
my ($index_biblios, $index_authorities); |
124 |
my ($index_biblios, $index_authorities); |
| 116 |
my (@biblionumbers); |
125 |
my (@biblionumbers); |
| 117 |
my ($offset, $length); |
126 |
my ($offset, $length, $file); |
| 118 |
|
127 |
|
| 119 |
$|=1; # flushes output |
128 |
$|=1; # flushes output |
| 120 |
|
129 |
|
|
Lines 127-143
GetOptions(
Link Here
|
| 127 |
'v|verbose+' => \$verbose, |
136 |
'v|verbose+' => \$verbose, |
| 128 |
'offset=i' => \$offset, |
137 |
'offset=i' => \$offset, |
| 129 |
'length=i' => \$length, |
138 |
'length=i' => \$length, |
|
|
139 |
'f|file=s' => \$file, |
| 130 |
'h|help' => \$help, |
140 |
'h|help' => \$help, |
| 131 |
'man' => \$man, |
141 |
'man' => \$man, |
| 132 |
); |
142 |
); |
| 133 |
|
143 |
|
|
|
144 |
pod2usage(1) if $help; |
| 145 |
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man; |
| 146 |
|
| 134 |
# Default is to do both |
147 |
# Default is to do both |
| 135 |
unless ($index_authorities || $index_biblios) { |
148 |
unless ($index_authorities || $index_biblios) { |
| 136 |
$index_authorities = $index_biblios = 1; |
149 |
$index_authorities = $index_biblios = 1; |
| 137 |
} |
150 |
} |
| 138 |
|
151 |
|
| 139 |
pod2usage(1) if $help; |
152 |
if ($file){ |
| 140 |
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man; |
153 |
if ($offset || $length || @biblionumbers){ |
|
|
154 |
printf "With options --file, you can't have options --length, --offset, and -bn" . "\n"; |
| 155 |
pod2usage(1); |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
if (@biblionumbers){ |
| 160 |
if ($length || $offset){ |
| 161 |
printf "With option -bn, you can't have options --length, --offset" . "\n"; |
| 162 |
pod2usage(1); |
| 163 |
} |
| 164 |
} |
| 141 |
|
165 |
|
| 142 |
if ($offset || $length){ |
166 |
if ($offset || $length){ |
| 143 |
if ( $index_biblios && $index_authorities){ |
167 |
if ( $index_biblios && $index_authorities){ |
|
Lines 149-188
if ($offset || $length){
Link Here
|
| 149 |
sanity_check(); |
173 |
sanity_check(); |
| 150 |
|
174 |
|
| 151 |
my $next; |
175 |
my $next; |
| 152 |
if ($index_biblios) { |
176 |
|
| 153 |
_log(1, "Indexing biblios\n"); |
177 |
if ($file){ |
| 154 |
if (@biblionumbers) { |
178 |
my @bibnums; |
| 155 |
$next = sub { |
179 |
my $i = 0; |
| 156 |
my $r = shift @biblionumbers; |
180 |
my $input = $file; |
| 157 |
return () unless defined $r; |
181 |
my $parser = Text::CSV->new(); |
| 158 |
return ($r, Koha::BiblioUtils->get_from_biblionumber($r, item_data => 1 )); |
182 |
open ( my $csv, "<", $input ); |
| 159 |
}; |
183 |
|
| 160 |
} else { |
184 |
while (<$csv>) { |
| 161 |
my $records = Koha::BiblioUtils->get_all_biblios_iterator($offset, $length); |
185 |
if ($parser->parse($_)){ |
| 162 |
$next = sub { |
186 |
my @columns = $parser->fields(); |
| 163 |
$records->next(); |
187 |
@bibnums[$i] = @columns; |
|
|
188 |
$i++; |
| 164 |
} |
189 |
} |
| 165 |
} |
190 |
} |
| 166 |
do_reindex($next, $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX); |
191 |
close $csv; |
| 167 |
} |
192 |
|
| 168 |
if ($index_authorities) { |
193 |
if (@bibnums){ |
| 169 |
_log(1, "Indexing authorities\n"); |
194 |
my $type = shift @bibnums; |
| 170 |
if (@biblionumbers) { |
195 |
if ($type eq "biblionumber"){ |
| 171 |
$next = sub { |
196 |
_log(1, "Indexing biblios\n"); |
| 172 |
my $r = shift @biblionumbers; |
197 |
$next = sub { |
| 173 |
return () unless defined $r; |
198 |
my $bibnum = shift @bibnums; |
| 174 |
my $a = Koha::MetadataRecord::Authority->get_from_authid($r); |
199 |
return () unless defined $bibnum; |
| 175 |
return ($r, $a->record); |
200 |
return ($bibnum, Koha::BiblioUtils->get_from_biblionumber($bibnum, item_data => 1 )); |
| 176 |
}; |
201 |
}; |
| 177 |
} else { |
202 |
do_reindex($next, $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX); |
| 178 |
my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator($offset, $length); |
203 |
|
| 179 |
$next = sub { |
204 |
} elsif ($type eq "authid"){ |
| 180 |
$records->next(); |
205 |
_log(1, "Indexing authorities\n"); |
|
|
206 |
$next = sub { |
| 207 |
my $authid = shift @bibnums; |
| 208 |
return () unless defined $authid; |
| 209 |
return ($authid,Koha::MetadataRecord::Authority->get_from_authid($authid)); |
| 210 |
}; |
| 211 |
do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); |
| 181 |
} |
212 |
} |
| 182 |
} |
213 |
} |
| 183 |
do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); |
214 |
|
|
|
215 |
} else { |
| 216 |
if ($index_biblios) { |
| 217 |
_log(1, "Indexing biblios\n"); |
| 218 |
|
| 219 |
if (@biblionumbers) { |
| 220 |
$next = sub { |
| 221 |
my $r = shift @biblionumbers; |
| 222 |
return () unless defined $r; |
| 223 |
return ($r, Koha::BiblioUtils->get_from_biblionumber($r, item_data => 1 )); |
| 224 |
}; |
| 225 |
} else { |
| 226 |
my $records = Koha::BiblioUtils->get_all_biblios_iterator($offset, $length); |
| 227 |
$next = sub { |
| 228 |
$records->next(); |
| 229 |
} |
| 230 |
} |
| 231 |
do_reindex($next, $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX); |
| 232 |
} |
| 233 |
if ($index_authorities) { |
| 234 |
_log(1, "Indexing authorities\n"); |
| 235 |
|
| 236 |
if (@biblionumbers) { |
| 237 |
$next = sub { |
| 238 |
my $r = shift @biblionumbers; |
| 239 |
return () unless defined $r; |
| 240 |
return ($r,Koha::MetadataRecord::Authority->get_from_authid($r)); |
| 241 |
}; |
| 242 |
} else { |
| 243 |
my $records = Koha::MetadataRecord::Authority->get_all_authorities_iterator($offset, $length); |
| 244 |
$next = sub { |
| 245 |
$records->next(); |
| 246 |
} |
| 247 |
} |
| 248 |
do_reindex($next, $Koha::SearchEngine::Elasticsearch::AUTHORITIES_INDEX); |
| 249 |
} |
| 184 |
} |
250 |
} |
| 185 |
|
251 |
|
|
|
252 |
|
| 186 |
sub do_reindex { |
253 |
sub do_reindex { |
| 187 |
my ( $next, $index_name ) = @_; |
254 |
my ( $next, $index_name ) = @_; |
| 188 |
|
255 |
|
| 189 |
- |
|
|