From bfd7a474c7a7c41cf7e42d59e6d21c2889f586b8 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 12 Oct 2015 16:45:48 +0100 Subject: [PATCH] Bug 12478: [DO NOT PUSH] script to generate the mappings yaml file --- mappings_to_yaml.pl | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 mappings_to_yaml.pl diff --git a/mappings_to_yaml.pl b/mappings_to_yaml.pl new file mode 100644 index 0000000..8f3125f --- /dev/null +++ b/mappings_to_yaml.pl @@ -0,0 +1,123 @@ +use Modern::Perl; +use YAML::XS; + +my $filename = '/tmp/mapping_es.text'; +# The format of this file is: +# ('authorities','Meeting-name-see-also-from',FALSE,FALSE,'','511acdefghjklnpqstvxyz',NULL,'511acdefghjklnpqstvxyz'); +my $indexes; +open my $fh, '<', $filename or die "no file"; +while ( my $line = <$fh> ) { + chomp $line; + next unless $line; + if ( $line =~ m|\('(\w+)','([^']*)','?(\w+)'?,'?([^']*)'?,'?([^']*)'?,'?([^']*)'?,'?([^']*)'?,'?([^']*)'?\);| ) { + my $indexname = $1; + my $mapping = $2; + my $facet = $3 eq 'TRUE'; + my $suggestible = $4 eq 'TRUE'; + my $type = $5; + my $marc21 = $6; + my $unimarc = $7; + my $normarc = $8; + $indexes->{$indexname}{$mapping}{type} = $type; + $indexes->{$indexname}{$mapping}{label} = $mapping; + for my $marc_type ( qw( marc21 unimarc normarc ) ) { + my $marc_field = ${eval('\$' . $marc_type)}; + next if not $marc_field or $marc_field eq 'NULL'; + push @{ $indexes->{$indexname}{$mapping}{mappings}}, { + facet => $facet, + suggestible => $suggestible, + sort => undef, + marc_field => $marc_field, + marc_type => $marc_type, + } + } + } +} + +# Additional rows +#('biblios','author',TRUE,TRUE,FALSE,'string','700a','700a','700a'); -- no sorting on the +#('biblios','author',FALSE,FALSE,FALSE,'string','245c','701','245c'); -- extra author fields +#('biblios','notforloan',FALSE,FALSE,'number','9527','995o','9527'); -- newly created + +push @{$indexes->{biblios}{author}{mappings}}, { + facet => 1, + suggestible => 1, + sort => 0, + marc_type => 'marc21', + marc_field => => '700a', +}; +push @{$indexes->{biblios}{author}{mappings}}, { + facet => 1, + suggestible => 1, + sort => 0, + marc_type => 'unimarc', + marc_field => => '700a', +}; +push @{$indexes->{biblios}{author}{mappings}}, { + facet => 1, + suggestible => 1, + sort => 0, + marc_type => 'normarc', + marc_field => => '700a', +}; + +push @{$indexes->{biblios}{author}{mappings}}, { + facet => 0, + suggestible => 0, + sort => 0, + marc_type => 'marc21', + marc_field => '245c', +}; +push @{$indexes->{biblios}{author}{mappings}}, { + facet => 0, + suggestible => 0, + sort => 0, + marc_type => 'unimarc', + marc_field => '701', +}; +push @{$indexes->{biblios}{author}{mappings}}, { + facet => 0, + suggestible => 0, + sort => 0, + marc_type => 'normarc', + marc_field => '245c', +}; + +$indexes->{biblios}{notforloan}{type} = 'number'; +$indexes->{biblios}{notforloan}{label} = 'notforloan'; +push @{$indexes->{biblios}{notforloan}{mappings}}, { + facet => 0, + suggestible => 0, + sort => undef, + marc_type => 'marc21', + marc_field => '9527', +}; +push @{$indexes->{biblios}{notforloan}{mappings}}, { + facet => 0, + suggestible => 0, + sort => undef, + marc_type => 'unimarc', + marc_field => '995o', +}; +push @{$indexes->{biblios}{notforloan}{mappings}}, { + facet => 0, + suggestible => 0, + sort => undef, + marc_type => 'normarc', + marc_field => '9527', +}; + +# Resort to group by marc_type +while ( my ( $index_name, $fields ) = each %$indexes ) { + while ( my ( $field_name, $data ) = each %$fields ) { + $indexes->{$index_name}{$field_name}{mappings} = [ + sort { $a->{marc_type} cmp $b->{marc_type} || $a->{marc_field} cmp $b->{marc_field} } @{ $indexes->{$index_name}{$field_name}{mappings} } + ]; + } +} + +my $yaml = Dump $indexes;; + +open $fh, '>', '/tmp/elastic_search_mappings.yaml'; +print $fh $yaml; +close $fh; -- 2.1.0