From bc3b0daaa42122045775c94b6fae59af63009465 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Wed, 10 Jun 2015 14:35:33 +1200 Subject: [PATCH] Bug 12478: change the schema for storing mappings This makes the mapping schema a proper many-to-many relational structure, which is a little more fiddly to work with, but will make things like editors for it easier to write. Signed-off-by: Nick Clemens Signed-off-by: Jesse Weaver Signed-off-by: Tomas Cohen Arazi Signed-off-by: Kyle M Hall Signed-off-by: Brendan Gallagher --- Koha/ElasticSearch.pm | 67 ++++---- Koha/Schema/Result/ElasticsearchMapping.pm | 105 ------------ Koha/Schema/Result/SearchField.pm | 122 ++++++++++++++ Koha/Schema/Result/SearchMarcMap.pm | 150 ++++++++++++++++++ Koha/Schema/Result/SearchMarcToField.pm | 99 ++++++++++++ .../data/mysql/elasticsearch_mapping.sql | 72 +++++++-- 6 files changed, 469 insertions(+), 146 deletions(-) delete mode 100644 Koha/Schema/Result/ElasticsearchMapping.pm create mode 100644 Koha/Schema/Result/SearchField.pm create mode 100644 Koha/Schema/Result/SearchMarcMap.pm create mode 100644 Koha/Schema/Result/SearchMarcToField.pm diff --git a/Koha/ElasticSearch.pm b/Koha/ElasticSearch.pm index 56afaeffc6..0f3443c307 100644 --- a/Koha/ElasticSearch.pm +++ b/Koha/ElasticSearch.pm @@ -174,10 +174,11 @@ sub get_elasticsearch_mappings { } } }; + my $marcflavour = lc C4::Context->preference('marcflavour'); $self->_foreach_mapping( sub { - my ( undef, $name, $type, $facet ) = @_; - + my ( $name, $type, $facet, $marc_type ) = @_; + return if $marc_type ne $marcflavour; # TODO if this gets any sort of complexity to it, it should # be broken out into its own function. @@ -221,19 +222,18 @@ sub get_fixer_rules { my @rules; $self->_foreach_mapping( sub { - my ( undef, $name, $type, $facet, $marcs ) = @_; - my $field = $marcs->{$marcflavour}; - return unless defined $marcs->{$marcflavour}; + my ( $name, $type, $facet, $marc_type, $marc_field ) = @_; + return if $marc_type ne $marcflavour; my $options = ''; # There's a bug when using 'split' with something that # selects a range # The split makes everything into nested arrays, but that's not # really a big deal, ES doesn't mind. - $options = '-split => 1' unless $field =~ m|_/| || $type eq 'sum'; - push @rules, "marc_map('$field','${name}', $options)"; + $options = '-split => 1' unless $marc_field =~ m|_/| || $type eq 'sum'; + push @rules, "marc_map('$marc_field','${name}', $options)"; if ($facet) { - push @rules, "marc_map('$field','${name}__facet', $options)"; + push @rules, "marc_map('$marc_field','${name}__facet', $options)"; } if ( $type eq 'boolean' ) { @@ -247,7 +247,7 @@ sub get_fixer_rules { } } ); - +die Dumper(\@rules); return \@rules; } @@ -255,8 +255,9 @@ sub get_fixer_rules { $self->_foreach_mapping( sub { - my ( $id, $name, $type, $facet, $marcs ) = @_; - my $marc = $marcs->{marc21}; + my ( $name, $type, $facet, $marc_type, $marc_field ) = @_; + return unless $marc_type eq 'marc21'; + print "Data comes from: " . $marc_field . "\n"; } ); @@ -267,10 +268,6 @@ In the provided function, the files are: =over 4 -=item C<$id> - -An ID number, corresponding to the entry in the database. - =item C<$name> The field name for elasticsearch (corresponds to the 'mapping' column in the @@ -285,11 +282,15 @@ The type for this value, e.g. 'string'. True if this value should be facetised. This only really makes sense if the field is understood by the facet processing code anyway. -=item C<$marc> +=item C<$marc_type> -A hashref containing the MARC field specifiers for each MARC type. It's quite -possible for this to be undefined if there is otherwise an entry in a -different MARC form. +A string that indicates the MARC type that this mapping is for, e.g. 'marc21', +'unimarc', 'normarc'. + +=item C<$marc_field> + +A string that describes the MARC field that contains the data to extract. +These are of a form suited to Catmandu's MARC fixers. =back @@ -302,20 +303,22 @@ sub _foreach_mapping { my $database = Koha::Database->new(); my $schema = $database->schema(); my $rs = - $schema->resultset('ElasticsearchMapping') - ->search( { indexname => $self->index } ); + $schema->resultset('SearchMarcMap') + ->search( { index_name => $self->index } ); for my $row ( $rs->all ) { - $sub->( - $row->id, - $row->mapping, - $row->type, - $row->facet, - { - marc21 => $row->marc21, - unimarc => $row->unimarc, - normarc => $row->normarc - } - ); + my $marc_type = $row->marc_type; + my $marc_field = $row->marc_field; + my $facet = $row->facet; + my $search_field = $row->search_fields(); + for my $sf ( $search_field->all ) { + $sub->( + $sf->name, + $sf->type, + $facet, + $marc_type, + $marc_field, + ); + } } } diff --git a/Koha/Schema/Result/ElasticsearchMapping.pm b/Koha/Schema/Result/ElasticsearchMapping.pm deleted file mode 100644 index e280704561..0000000000 --- a/Koha/Schema/Result/ElasticsearchMapping.pm +++ /dev/null @@ -1,105 +0,0 @@ -use utf8; -package Koha::Schema::Result::ElasticsearchMapping; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Koha::Schema::Result::ElasticsearchMapping - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("elasticsearch_mapping"); - -=head1 ACCESSORS - -=head2 id - - data_type: 'integer' - is_auto_increment: 1 - is_nullable: 0 - -=head2 mapping - - data_type: 'varchar' - is_nullable: 1 - size: 255 - -=head2 type - - data_type: 'varchar' - is_nullable: 0 - size: 255 - -=head2 facet - - data_type: 'tinyint' - default_value: 0 - is_nullable: 1 - -=head2 marc21 - - data_type: 'varchar' - is_nullable: 1 - size: 255 - -=head2 unimarc - - data_type: 'varchar' - is_nullable: 1 - size: 255 - -=head2 normarc - - data_type: 'varchar' - is_nullable: 1 - size: 255 - -=cut - -__PACKAGE__->add_columns( - "id", - { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "mapping", - { data_type => "varchar", is_nullable => 1, size => 255 }, - "type", - { data_type => "varchar", is_nullable => 0, size => 255 }, - "facet", - { data_type => "tinyint", default_value => 0, is_nullable => 1 }, - "marc21", - { data_type => "varchar", is_nullable => 1, size => 255 }, - "unimarc", - { data_type => "varchar", is_nullable => 1, size => 255 }, - "normarc", - { data_type => "varchar", is_nullable => 1, size => 255 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("id"); - - -# Created by DBIx::Class::Schema::Loader v0.07040 @ 2014-07-01 15:12:50 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:D9WpVp24RV/MGHktgXzdkQ - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/Koha/Schema/Result/SearchField.pm b/Koha/Schema/Result/SearchField.pm new file mode 100644 index 0000000000..45fd26cdd6 --- /dev/null +++ b/Koha/Schema/Result/SearchField.pm @@ -0,0 +1,122 @@ +use utf8; +package Koha::Schema::Result::SearchField; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::SearchField + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("search_field"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +=head2 name + + data_type: 'varchar' + is_nullable: 0 + size: 255 + +the name of the field as it will be stored in the search engine + +=head2 type + + data_type: 'enum' + extra: {list => ["string","date","number","boolean","sum"]} + is_nullable: 0 + +what type of data this holds, relevant when storing it + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "name", + { data_type => "varchar", is_nullable => 0, size => 255 }, + "type", + { + data_type => "enum", + extra => { list => ["string", "date", "number", "boolean", "sum"] }, + is_nullable => 0, + }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("name", ["name"]); + +=head1 RELATIONS + +=head2 search_marc_to_fields + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "search_marc_to_fields", + "Koha::Schema::Result::SearchMarcToField", + { "foreign.search_field_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +=head2 search_marc_maps + +Type: many_to_many + +Composing rels: L -> search_marc_map + +=cut + +__PACKAGE__->many_to_many("search_marc_maps", "search_marc_to_fields", "search_marc_map"); + + +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-06-10 14:32:07 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1pj98qkKkP9g0hJYExud0A + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/Koha/Schema/Result/SearchMarcMap.pm b/Koha/Schema/Result/SearchMarcMap.pm new file mode 100644 index 0000000000..45654a19b5 --- /dev/null +++ b/Koha/Schema/Result/SearchMarcMap.pm @@ -0,0 +1,150 @@ +use utf8; +package Koha::Schema::Result::SearchMarcMap; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::SearchMarcMap + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("search_marc_map"); + +=head1 ACCESSORS + +=head2 id + + data_type: 'integer' + is_auto_increment: 1 + is_nullable: 0 + +=head2 index_name + + data_type: 'enum' + extra: {list => ["biblios","authorities"]} + is_nullable: 0 + +what storage index this map is for + +=head2 marc_type + + data_type: 'enum' + extra: {list => ["marc21","unimarc","normarc"]} + is_nullable: 0 + +what MARC type this map is for + +=head2 marc_field + + data_type: 'varchar' + is_nullable: 0 + size: 255 + +the MARC specifier for this field + +=head2 facet + + data_type: 'tinyint' + default_value: 0 + is_nullable: 1 + +true if a facet field should be generated for this + +=cut + +__PACKAGE__->add_columns( + "id", + { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, + "index_name", + { + data_type => "enum", + extra => { list => ["biblios", "authorities"] }, + is_nullable => 0, + }, + "marc_type", + { + data_type => "enum", + extra => { list => ["marc21", "unimarc", "normarc"] }, + is_nullable => 0, + }, + "marc_field", + { data_type => "varchar", is_nullable => 0, size => 255 }, + "facet", + { data_type => "tinyint", default_value => 0, is_nullable => 1 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("id"); + +=head1 UNIQUE CONSTRAINTS + +=head2 C + +=over 4 + +=item * L + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->add_unique_constraint("index_name_2", ["index_name", "marc_type", "marc_field"]); + +=head1 RELATIONS + +=head2 search_marc_to_fields + +Type: has_many + +Related object: L + +=cut + +__PACKAGE__->has_many( + "search_marc_to_fields", + "Koha::Schema::Result::SearchMarcToField", + { "foreign.search_marc_map_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +=head2 search_fields + +Type: many_to_many + +Composing rels: L -> search_field + +=cut + +__PACKAGE__->many_to_many("search_fields", "search_marc_to_fields", "search_field"); + + +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-06-10 14:32:07 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9Xz04ajKUJXxwJ5pdo+cUQ + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/Koha/Schema/Result/SearchMarcToField.pm b/Koha/Schema/Result/SearchMarcToField.pm new file mode 100644 index 0000000000..c000c4122a --- /dev/null +++ b/Koha/Schema/Result/SearchMarcToField.pm @@ -0,0 +1,99 @@ +use utf8; +package Koha::Schema::Result::SearchMarcToField; + +# Created by DBIx::Class::Schema::Loader +# DO NOT MODIFY THE FIRST PART OF THIS FILE + +=head1 NAME + +Koha::Schema::Result::SearchMarcToField + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +=head1 TABLE: C + +=cut + +__PACKAGE__->table("search_marc_to_field"); + +=head1 ACCESSORS + +=head2 search_marc_map_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=head2 search_field_id + + data_type: 'integer' + is_foreign_key: 1 + is_nullable: 0 + +=cut + +__PACKAGE__->add_columns( + "search_marc_map_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "search_field_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, +); + +=head1 PRIMARY KEY + +=over 4 + +=item * L + +=item * L + +=back + +=cut + +__PACKAGE__->set_primary_key("search_marc_map_id", "search_field_id"); + +=head1 RELATIONS + +=head2 search_field + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "search_field", + "Koha::Schema::Result::SearchField", + { id => "search_field_id" }, + { is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" }, +); + +=head2 search_marc_map + +Type: belongs_to + +Related object: L + +=cut + +__PACKAGE__->belongs_to( + "search_marc_map", + "Koha::Schema::Result::SearchMarcMap", + { id => "search_marc_map_id" }, + { is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT" }, +); + + +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-06-10 14:32:07 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ZNdjnjdGpK+5P478RkCWnA + + +# You can replace this text with custom code or comments, and it will be preserved on regeneration +1; diff --git a/installer/data/mysql/elasticsearch_mapping.sql b/installer/data/mysql/elasticsearch_mapping.sql index 5edb989d79..a218c8be44 100644 --- a/installer/data/mysql/elasticsearch_mapping.sql +++ b/installer/data/mysql/elasticsearch_mapping.sql @@ -1,4 +1,7 @@ DROP TABLE IF EXISTS elasticsearch_mapping; +DROP TABLE IF EXISTS search_marc_to_field; +DROP TABLE IF EXISTS search_field; +DROP TABLE IF EXISTS search_marc_map; CREATE TABLE `elasticsearch_mapping` ( `id` int(11) NOT NULL AUTO_INCREMENT, `indexname` varchar(255) NOT NULL, @@ -11,21 +14,56 @@ CREATE TABLE `elasticsearch_mapping` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- This specifies the fields that will be stored in the search engine. +CREATE TABLE `search_field` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL COMMENT 'the name of the field as it will be stored in the search engine', + `type` ENUM('string', 'date', 'number', 'boolean', 'sum') NOT NULL COMMENT 'what type of data this holds, relevant when storing it', + PRIMARY KEY (`id`), + UNIQUE KEY (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- This contains a MARC field specifier for a given index, marc type, and marc +-- field. +CREATE TABLE `search_marc_map` ( + id int(11) NOT NULL AUTO_INCREMENT, + index_name ENUM('biblios','authorities') NOT NULL COMMENT 'what storage index this map is for', + marc_type ENUM('marc21', 'unimarc', 'normarc') NOT NULL COMMENT 'what MARC type this map is for', + marc_field VARCHAR(255) NOT NULL COMMENT 'the MARC specifier for this field', + `facet` boolean DEFAULT FALSE COMMENT 'true if a facet field should be generated for this', + PRIMARY KEY(`id`), + INDEX (`index_name`), + UNIQUE KEY (index_name, marc_type, marc_field) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- This joins the two search tables together. We can have any combination: +-- one marc field could have many search fields (maybe you want one value +-- to go to 'author' and 'corporate-author) and many marc fields could go +-- to one search field (e.g. all the various author fields going into +-- 'author'.) +CREATE TABLE `search_marc_to_field` ( + search_marc_map_id int(11) NOT NULL, + search_field_id int(11) NOT NULL, + PRIMARY KEY(search_marc_map_id, search_field_id), + FOREIGN KEY(search_marc_map_id) REFERENCES search_marc_map(id), + FOREIGN KEY(search_field_id) REFERENCES search_field(id) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','llength',FALSE,'','leader_/1-5',NULL,'leader_/1-5'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','rtype',FALSE,'','leader_/6',NULL,'leader_/6'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','bib-level',FALSE,'','leader_/7',NULL,'leader_/7'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','control-number',FALSE,'','001',NULL,'001'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'',NULL,'001',NULL); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string',NULL,'001',NULL); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','date-time-last-modified',FALSE,'','005','099d',NULL); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','microform-generation',FALSE,'','007_/11',NULL,'007_/11'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','material-type',FALSE,'','007','200b','007'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','material-type',FALSE,'','007','','007'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ff7-00',FALSE,'','007_/1',NULL,'007_/1'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ff7-01',FALSE,'','007_/2',NULL,'007_/2'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ff7-02',FALSE,'','007_/3',NULL,'007_/3'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ff7-01-02',FALSE,'','007_/1-2',NULL,'007_/1-2'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','date-entered-on-file',FALSE,'','008_/1-5','099c','008_/1-5'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','pubdate',FALSE,'','008_/7-10','100a_/9-12','008_/7-10'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','pl',FALSE,'','008_/15-17','210a','008_/15-17'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','pl',FALSE,'','008_/15-17','','008_/15-17'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ta',FALSE,'','008_/22','100a_/17','008_/22'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ff8-23',FALSE,'','008_/23',NULL,'008_/23'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ff8-29',FALSE,'','008_/29','105a_/8','008_/29'); @@ -33,7 +71,7 @@ INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `m INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','bio',FALSE,'','008_/34','105a_/12','008_/34'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ln',FALSE,'','008_/35-37','101a','008_/35-37'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','ctype',FALSE,'','008_/24-27','105a_/4-7','008_/24-27'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','record-source',FALSE,'','008_/39','995c','008_/39'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','record-source',FALSE,'','008_/39','','008_/39'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','lc-cardnumber',FALSE,'','010','995j','010'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','lc-cardnumber',FALSE,'','011',NULL,NULL); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','identifier-standard',FALSE,'','010',NULL,'010'); @@ -54,7 +92,7 @@ INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `m INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','author',TRUE,'string','110a','200g','110a'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','author',TRUE,'string','111a',NULL,'111a'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','author',TRUE,'string','700a','700a','700a'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','author',FALSE,'string','245c','701','245c'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','author',TRUE,'string','245c','701','245c'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','title',FALSE,'string','245a','200a','245a'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','title',FALSE,'string','246','200c','246'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','title',FALSE,'string','247','200d','247'); @@ -132,11 +170,11 @@ INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `m INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','subject',TRUE,'string','653a','610','653'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-classification',FALSE,'','952o','995k','952o'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-classification',FALSE,'',NULL,'686',NULL); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'','999c','001','999c'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'',NULL,'0909',NULL); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string','999c','001','999c'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','local-number',FALSE,'string',NULL,'0909',NULL); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','itype',TRUE,'string','942c','200b','942c'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','itype',TRUE,'string','952y','995r','952y'); -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','acqdate',FALSE,'date','952d','9955','952y'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','acqdate',FALSE,'date','952d','9955','952d'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','place',TRUE,'string','260a','210a','260a'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','publisher',TRUE,'string','260b','210c','260b'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','copydate',TRUE,'date','260c',NULL,'260c'); -- No copydate for unimarc? Seems strange. @@ -192,7 +230,7 @@ INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `m INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('biblios','an',FALSE,'number',NULL,'6219',NULL); -- Authorities: incomplete -INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Local-Number',FALSE,'string','001',NULL,'001'); +INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','local-number',FALSE,'string','001',NULL,'001'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','authtype',FALSE,'','942a',NULL,'942a'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Kind-of-record',FALSE,'','008_/9',NULL,'008_/9'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Descriptive-cataloging-rules',FALSE,'','008_/10',NULL,'008_/10'); @@ -235,3 +273,19 @@ INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `m INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Meeting-name-see-also-from',FALSE,'','511acdefghjklnpqstvxyz',NULL,'511acdefghjklnpqstvxyz'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','See-also-from',FALSE,'','511acdefghjklnpqstvxyz',NULL,'511acdefghjklnpqstvxyz'); INSERT INTO `elasticsearch_mapping` (`indexname`, `mapping`, `facet`, `type`, `marc21`, `unimarc`, `normarc`) VALUES ('authorities','Match',FALSE,'','511acdefghjklnpqstvxyz',NULL,'511acdefghjklnpqstvxyz'); + +-- temporary to convert into new table form +insert into search_marc_map(index_name, marc_type, marc_field, facet) select distinct indexname, 'marc21', marc21, facet from elasticsearch_mapping where marc21 is not null; +insert into search_marc_map(index_name, marc_type, marc_field, facet) select distinct indexname, 'unimarc', unimarc, facet from elasticsearch_mapping where unimarc is not null; +insert into search_marc_map(index_name, marc_type, marc_field, facet) select distinct indexname, 'normarc', normarc, facet from elasticsearch_mapping where normarc is not null; +insert into search_field (name, type) select distinct mapping, type from elasticsearch_mapping; + +insert into search_marc_to_field(search_field_id, search_marc_map_id) select search_field.id,search_marc_map.id from search_field, search_marc_map, elasticsearch_mapping where elasticsearch_mapping.mapping=search_field.name AND elasticsearch_mapping.marc21=search_marc_map.marc_field AND search_marc_map.marc_type='marc21' AND index_name='biblios'; +insert into search_marc_to_field(search_field_id, search_marc_map_id) select search_field.id,search_marc_map.id from search_field, search_marc_map, elasticsearch_mapping where elasticsearch_mapping.mapping=search_field.name AND elasticsearch_mapping.marc21=search_marc_map.marc_field AND search_marc_map.marc_type='unimarc' AND index_name='biblios'; +insert into search_marc_to_field(search_field_id, search_marc_map_id) select search_field.id,search_marc_map.id from search_field, search_marc_map, elasticsearch_mapping where elasticsearch_mapping.mapping=search_field.name AND elasticsearch_mapping.marc21=search_marc_map.marc_field AND search_marc_map.marc_type='normarc' AND index_name='biblios'; + +insert into search_marc_to_field(search_field_id, search_marc_map_id) select search_field.id,search_marc_map.id from search_field, search_marc_map, elasticsearch_mapping where elasticsearch_mapping.mapping=search_field.name AND elasticsearch_mapping.marc21=search_marc_map.marc_field AND search_marc_map.marc_type='marc21' AND index_name='authorities'; +insert into search_marc_to_field(search_field_id, search_marc_map_id) select search_field.id,search_marc_map.id from search_field, search_marc_map, elasticsearch_mapping where elasticsearch_mapping.mapping=search_field.name AND elasticsearch_mapping.marc21=search_marc_map.marc_field AND search_marc_map.marc_type='unimarc' AND index_name='authorities'; +insert into search_marc_to_field(search_field_id, search_marc_map_id) select search_field.id,search_marc_map.id from search_field, search_marc_map, elasticsearch_mapping where elasticsearch_mapping.mapping=search_field.name AND elasticsearch_mapping.marc21=search_marc_map.marc_field AND search_marc_map.marc_type='normarc' AND index_name='authorities'; + +drop table elasticsearch_mapping; -- 2.39.2