Lines 34-41
use Search::Elasticsearch;
Link Here
|
34 |
use Try::Tiny; |
34 |
use Try::Tiny; |
35 |
use YAML::Syck; |
35 |
use YAML::Syck; |
36 |
|
36 |
|
37 |
use Data::Dumper; # TODO remove |
|
|
38 |
|
39 |
__PACKAGE__->mk_ro_accessors(qw( index )); |
37 |
__PACKAGE__->mk_ro_accessors(qw( index )); |
40 |
__PACKAGE__->mk_accessors(qw( sort_fields )); |
38 |
__PACKAGE__->mk_accessors(qw( sort_fields )); |
41 |
|
39 |
|
Lines 319-356
sub get_fixer_rules {
Link Here
|
319 |
my $marcflavour = lc C4::Context->preference('marcflavour'); |
317 |
my $marcflavour = lc C4::Context->preference('marcflavour'); |
320 |
my @rules; |
318 |
my @rules; |
321 |
|
319 |
|
|
|
320 |
my $sort_fields = $self->sort_fields(); |
322 |
$self->_foreach_mapping( |
321 |
$self->_foreach_mapping( |
323 |
sub { |
322 |
sub { |
324 |
my ( $name, $type, $facet, $suggestible, $sort, $marc_type, $marc_field ) = @_; |
323 |
my ( $name, $type, $facet, $suggestible, $sort, $marc_type, $marc_field ) = @_; |
325 |
return if $marc_type ne $marcflavour; |
324 |
return if $marc_type ne $marcflavour; |
326 |
my $options =''; |
325 |
my $options = ($marc_field =~ m|_/| || $type eq 'sum') ? '' : "join:' '"; |
327 |
|
326 |
|
328 |
push @rules, "marc_map('$marc_field','${name}.\$append', $options)"; |
327 |
push @rules, "marc_map('$marc_field','${name}.\$append', $options)"; |
|
|
328 |
if ($marc_field !~ m|_/| && ($type eq '' || $type eq 'string')) { |
329 |
# Handle linked fields |
330 |
my $tag = substr($marc_field, 0, 3); |
331 |
my $subfields = substr($marc_field, 3); |
332 |
$subfields = 'abcdefghijklmnopqrstuvwxyz' unless $subfields; |
333 |
my $rule = "{\$6/0-2/=\\$tag}"; |
334 |
# Add dollars and rules to subfields |
335 |
$subfields =~ s/(.)/\$$1$rule/g; |
336 |
# Create a marc_spec rule to select correct 880 fields |
337 |
push @rules, "marc_spec('880${subfields}','${name}.\$append', $options)"; |
338 |
} |
329 |
if ($facet) { |
339 |
if ($facet) { |
330 |
push @rules, "marc_map('$marc_field','${name}__facet.\$append', $options)"; |
340 |
push @rules, "marc_map('$marc_field','${name}__facet.\$append', $options)"; |
331 |
} |
341 |
} |
332 |
if ($suggestible) { |
342 |
if ($suggestible) { |
333 |
push @rules, |
343 |
push @rules, "marc_map('$marc_field','${name}__suggestion.input.\$append', $options)"; |
334 |
#"marc_map('$marc_field','${name}__suggestion.input.\$append', '')"; #must not have nested data structures in .input |
|
|
335 |
"marc_map('$marc_field','${name}__suggestion.input.\$append')"; |
336 |
} |
344 |
} |
337 |
if ( $type eq 'boolean' ) { |
345 |
if ( $type eq 'boolean' ) { |
338 |
|
|
|
339 |
# boolean gets special handling, basically if it doesn't exist, |
346 |
# boolean gets special handling, basically if it doesn't exist, |
340 |
# it's added and set to false. Otherwise we can't query it. |
347 |
# it's added and set to false. Otherwise we can't query it. |
341 |
push @rules, |
348 |
push @rules, |
342 |
"unless exists('$name') add_field('$name', 0) end"; |
349 |
"unless exists('$name') add_field('$name', false) end"; |
343 |
} |
350 |
} |
344 |
if ($type eq 'sum' ) { |
351 |
if ($type eq 'sum' ) { |
345 |
push @rules, "sum('$name')"; |
352 |
push @rules, "sum('$name')"; |
|
|
353 |
} elsif ($type eq 'isbn') { |
354 |
push @rules, qq{ |
355 |
do list(path:isbn, var:c) |
356 |
copy_field(c, isbn_tmp.\$append) |
357 |
isbn_versions(c) |
358 |
copy_field(c, isbn_tmp.\$append) |
359 |
end |
360 |
move_field(isbn_tmp, isbn) |
361 |
}; |
346 |
} |
362 |
} |
347 |
if ($self->sort_fields()->{$name}) { |
363 |
|
348 |
if ($sort || !defined $sort) { |
364 |
if (defined $sort_fields->{$name}) { |
349 |
push @rules, "marc_map('$marc_field','${name}__sort.\$append', $options)"; |
365 |
push @rules, "marc_map('$marc_field','${name}__sort.\$append', $options)"; |
350 |
} |
|
|
351 |
} |
366 |
} |
352 |
} |
367 |
} |
353 |
); |
368 |
); |
|
|
369 |
# Merge sort fields into a single entry |
370 |
foreach my $field (keys $sort_fields) { |
371 |
push @rules, "join_field('${field}__sort', ' ')"; |
372 |
} |
354 |
|
373 |
|
355 |
push @rules, "move_field(_id,es_id)"; #Also you must set the Catmandu::Store::ElasticSearch->new(key_prefix: 'es_'); |
374 |
push @rules, "move_field(_id,es_id)"; #Also you must set the Catmandu::Store::ElasticSearch->new(key_prefix: 'es_'); |
356 |
return \@rules; |
375 |
return \@rules; |
357 |
- |
|
|