|
Line 0
Link Here
|
| 0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
use YAML::XS; |
| 3 |
|
| 4 |
my $filename = '/tmp/mapping_es.text'; |
| 5 |
# The format of this file is: |
| 6 |
# ('authorities','Meeting-name-see-also-from',FALSE,FALSE,'','511acdefghjklnpqstvxyz',NULL,'511acdefghjklnpqstvxyz'); |
| 7 |
my $indexes; |
| 8 |
open my $fh, '<', $filename or die "no file"; |
| 9 |
while ( my $line = <$fh> ) { |
| 10 |
chomp $line; |
| 11 |
next unless $line; |
| 12 |
if ( $line =~ m|\('(\w+)','([^']*)','?(\w+)'?,'?([^']*)'?,'?([^']*)'?,'?([^']*)'?,'?([^']*)'?,'?([^']*)'?\);| ) { |
| 13 |
my $indexname = $1; |
| 14 |
my $mapping = $2; |
| 15 |
my $facet = $3 eq 'TRUE'; |
| 16 |
my $suggestible = $4 eq 'TRUE'; |
| 17 |
my $type = $5; |
| 18 |
my $marc21 = $6; |
| 19 |
my $unimarc = $7; |
| 20 |
my $normarc = $8; |
| 21 |
$indexes->{$indexname}{$mapping}{type} = $type; |
| 22 |
$indexes->{$indexname}{$mapping}{label} = $mapping; |
| 23 |
for my $marc_type ( qw( marc21 unimarc normarc ) ) { |
| 24 |
my $marc_field = ${eval('\$' . $marc_type)}; |
| 25 |
next if not $marc_field or $marc_field eq 'NULL'; |
| 26 |
push @{ $indexes->{$indexname}{$mapping}{mappings}}, { |
| 27 |
facet => $facet, |
| 28 |
suggestible => $suggestible, |
| 29 |
sort => undef, |
| 30 |
marc_field => $marc_field, |
| 31 |
marc_type => $marc_type, |
| 32 |
} |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
# Additional rows |
| 38 |
#('biblios','author',TRUE,TRUE,FALSE,'string','700a','700a','700a'); -- no sorting on the |
| 39 |
#('biblios','author',FALSE,FALSE,FALSE,'string','245c','701','245c'); -- extra author fields |
| 40 |
#('biblios','notforloan',FALSE,FALSE,'number','9527','995o','9527'); -- newly created |
| 41 |
|
| 42 |
push @{$indexes->{biblios}{author}{mappings}}, { |
| 43 |
facet => 1, |
| 44 |
suggestible => 1, |
| 45 |
sort => 0, |
| 46 |
marc_type => 'marc21', |
| 47 |
marc_field => => '700a', |
| 48 |
}; |
| 49 |
push @{$indexes->{biblios}{author}{mappings}}, { |
| 50 |
facet => 1, |
| 51 |
suggestible => 1, |
| 52 |
sort => 0, |
| 53 |
marc_type => 'unimarc', |
| 54 |
marc_field => => '700a', |
| 55 |
}; |
| 56 |
push @{$indexes->{biblios}{author}{mappings}}, { |
| 57 |
facet => 1, |
| 58 |
suggestible => 1, |
| 59 |
sort => 0, |
| 60 |
marc_type => 'normarc', |
| 61 |
marc_field => => '700a', |
| 62 |
}; |
| 63 |
|
| 64 |
push @{$indexes->{biblios}{author}{mappings}}, { |
| 65 |
facet => 0, |
| 66 |
suggestible => 0, |
| 67 |
sort => 0, |
| 68 |
marc_type => 'marc21', |
| 69 |
marc_field => '245c', |
| 70 |
}; |
| 71 |
push @{$indexes->{biblios}{author}{mappings}}, { |
| 72 |
facet => 0, |
| 73 |
suggestible => 0, |
| 74 |
sort => 0, |
| 75 |
marc_type => 'unimarc', |
| 76 |
marc_field => '701', |
| 77 |
}; |
| 78 |
push @{$indexes->{biblios}{author}{mappings}}, { |
| 79 |
facet => 0, |
| 80 |
suggestible => 0, |
| 81 |
sort => 0, |
| 82 |
marc_type => 'normarc', |
| 83 |
marc_field => '245c', |
| 84 |
}; |
| 85 |
|
| 86 |
$indexes->{biblios}{notforloan}{type} = 'number'; |
| 87 |
$indexes->{biblios}{notforloan}{label} = 'notforloan'; |
| 88 |
push @{$indexes->{biblios}{notforloan}{mappings}}, { |
| 89 |
facet => 0, |
| 90 |
suggestible => 0, |
| 91 |
sort => undef, |
| 92 |
marc_type => 'marc21', |
| 93 |
marc_field => '9527', |
| 94 |
}; |
| 95 |
push @{$indexes->{biblios}{notforloan}{mappings}}, { |
| 96 |
facet => 0, |
| 97 |
suggestible => 0, |
| 98 |
sort => undef, |
| 99 |
marc_type => 'unimarc', |
| 100 |
marc_field => '995o', |
| 101 |
}; |
| 102 |
push @{$indexes->{biblios}{notforloan}{mappings}}, { |
| 103 |
facet => 0, |
| 104 |
suggestible => 0, |
| 105 |
sort => undef, |
| 106 |
marc_type => 'normarc', |
| 107 |
marc_field => '9527', |
| 108 |
}; |
| 109 |
|
| 110 |
# Resort to group by marc_type |
| 111 |
while ( my ( $index_name, $fields ) = each %$indexes ) { |
| 112 |
while ( my ( $field_name, $data ) = each %$fields ) { |
| 113 |
$indexes->{$index_name}{$field_name}{mappings} = [ |
| 114 |
sort { $a->{marc_type} cmp $b->{marc_type} || $a->{marc_field} cmp $b->{marc_field} } @{ $indexes->{$index_name}{$field_name}{mappings} } |
| 115 |
]; |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
my $yaml = Dump $indexes;; |
| 120 |
|
| 121 |
open $fh, '>', '/tmp/elastic_search_mappings.yaml'; |
| 122 |
print $fh $yaml; |
| 123 |
close $fh; |