Lines 84-97
use constant {
Link Here
|
84 |
Converts C<MARC::Records> C<$records> to Elasticsearch documents and performs |
84 |
Converts C<MARC::Records> C<$records> to Elasticsearch documents and performs |
85 |
an update request for these records on the Elasticsearch index. |
85 |
an update request for these records on the Elasticsearch index. |
86 |
|
86 |
|
87 |
The values in the arrays must match up, and the 999$c value in the MARC record |
|
|
88 |
will be rewritten using the values in C<$biblionums> to ensure they are correct. |
89 |
If C<$biblionums> is C<undef>, this won't happen, so in that case you should make |
90 |
sure that 999$c is correct. |
91 |
|
92 |
Note that this will modify the original record if C<$biblionums> is supplied. |
93 |
If that's a problem, clone them first. |
94 |
|
95 |
=over 4 |
87 |
=over 4 |
96 |
|
88 |
|
97 |
=item C<$biblionums> |
89 |
=item C<$biblionums> |
Lines 110-126
Arrayref of C<MARC::Record>s.
Link Here
|
110 |
sub update_index { |
102 |
sub update_index { |
111 |
my ($self, $biblionums, $records) = @_; |
103 |
my ($self, $biblionums, $records) = @_; |
112 |
|
104 |
|
113 |
if ($biblionums) { |
|
|
114 |
$self->_sanitise_records($biblionums, $records); |
115 |
} |
116 |
|
117 |
my $conf = $self->get_elasticsearch_params(); |
105 |
my $conf = $self->get_elasticsearch_params(); |
118 |
my $elasticsearch = $self->get_elasticsearch(); |
106 |
my $elasticsearch = $self->get_elasticsearch(); |
119 |
my $documents = $self->marc_records_to_documents($records); |
107 |
my $documents = $self->marc_records_to_documents($records); |
120 |
my @body; |
108 |
my @body; |
121 |
|
109 |
|
122 |
foreach my $document_info (@{$documents}) { |
110 |
for (my $i=0; $i < scalar @$biblionums; $i++) { |
123 |
my ($id, $document) = @{$document_info}; |
111 |
my $id = $biblionums->[$i]; |
|
|
112 |
my $document = $documents->[$i]; |
124 |
push @body, { |
113 |
push @body, { |
125 |
index => { |
114 |
index => { |
126 |
_id => $id |
115 |
_id => $id |
Lines 382-409
sub index_exists {
Link Here
|
382 |
); |
371 |
); |
383 |
} |
372 |
} |
384 |
|
373 |
|
385 |
sub _sanitise_records { |
|
|
386 |
my ($self, $biblionums, $records) = @_; |
387 |
|
388 |
confess "Unequal number of values in \$biblionums and \$records." if (@$biblionums != @$records); |
389 |
|
390 |
my $c = @$biblionums; |
391 |
for (my $i=0; $i<$c; $i++) { |
392 |
my $bibnum = $biblionums->[$i]; |
393 |
my $rec = $records->[$i]; |
394 |
# I've seen things you people wouldn't believe. Attack ships on fire |
395 |
# off the shoulder of Orion. I watched C-beams glitter in the dark near |
396 |
# the Tannhauser gate. MARC records where 999$c doesn't match the |
397 |
# biblionumber column. All those moments will be lost in time... like |
398 |
# tears in rain... |
399 |
if ( $rec ) { |
400 |
$rec->delete_fields($rec->field('999')); |
401 |
# Make sure biblionumber is a string. Elasticsearch would consider int and string different IDs. |
402 |
$rec->append_fields(MARC::Field->new('999','','','c' => "" . $bibnum, 'd' => "" . $bibnum)); |
403 |
} |
404 |
} |
405 |
} |
406 |
|
407 |
1; |
374 |
1; |
408 |
|
375 |
|
409 |
__END__ |
376 |
__END__ |