Bugzilla – Attachment 56135 Details for
Bug 16838
Elasticsearch - mapping tables are not populated on new installs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 16838: ES - install mappings for new installs
Bug-16838-ES---install-mappings-for-new-installs.patch (text/plain), 5.08 KB, created by
Kyle M Hall (khall)
on 2016-10-11 08:22:56 UTC
(
hide
)
Description:
Bug 16838: ES - install mappings for new installs
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2016-10-11 08:22:56 UTC
Size:
5.08 KB
patch
obsolete
>From 4628d2708085d4d7e4e1e0178265b859f322b3f9 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 29 Sep 2016 10:18:27 +0100 >Subject: [PATCH] Bug 16838: ES - install mappings for new installs > >The yaml file is not used to populate ES mapping tables (search_field, >search_marc_map and search_marc_to_field) when doing a fresh install. > >We need to insert them, otherwise ES will be unusable. > >Test plan: >Create a new install and confirm that the ES tables (search_field, >search_marc_map and search_marc_to_field) are correctly populated. > >Bonus points: Use an older DB (prior to 3.23.00.050), execute the >updatedatabase.pl script and confirm that the ES table are correctly >populated > >Signed-off-by: Nick Clemens <nick@bywatersolutions.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > Koha/ElasticSearch.pm | 21 +++++++++++++++++++++ > installer/data/mysql/updatedatabase.pl | 19 +++---------------- > installer/install.pl | 2 ++ > 3 files changed, 26 insertions(+), 16 deletions(-) > >diff --git a/Koha/ElasticSearch.pm b/Koha/ElasticSearch.pm >index d56c344..ee6f227 100644 >--- a/Koha/ElasticSearch.pm >+++ b/Koha/ElasticSearch.pm >@@ -22,11 +22,14 @@ use base qw(Class::Accessor); > use C4::Context; > > use Koha::Database; >+use Koha::SearchFields; >+use Koha::SearchMarcMaps; > > use Carp; > use JSON; > use Modern::Perl; > use Readonly; >+use YAML::Syck; > > use Data::Dumper; # TODO remove > >@@ -250,6 +253,24 @@ sub get_elasticsearch_mappings { > return $mappings; > } > >+sub reset_elasticsearch_mappings { >+ my $mappings_yaml = C4::Context->config('intranetdir') . '/admin/searchengine/elasticsearch/mappings.yaml'; >+ my $indexes = LoadFile( $mappings_yaml ); >+ >+ while ( my ( $index_name, $fields ) = each %$indexes ) { >+ while ( my ( $field_name, $data ) = each %$fields ) { >+ my $field_type = $data->{type}; >+ my $field_label = $data->{label}; >+ my $mappings = $data->{mappings}; >+ my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type }, { key => 'name' }); >+ for my $mapping ( @$mappings ) { >+ my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} }); >+ $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet}, suggestible => $mapping->{suggestible}, sort => $mapping->{sort} } ); >+ } >+ } >+ } >+} >+ > # This overrides the accessor provided by Class::Accessor so that if > # sort_fields isn't set, then it'll generate it. > sub sort_fields { >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index cda1b02..48f91e5 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -12274,9 +12274,9 @@ if ( $column_has_been_used ) { > > $DBversion = "3.23.00.050"; > if ( CheckVersion($DBversion) ) { >- use YAML::Syck; > use Koha::SearchMarcMaps; > use Koha::SearchFields; >+ use Koha::ElasticSearch; > > $dbh->do(q|INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) > VALUES('SearchEngine','Zebra','Choose Search Engine','','Choice')|); >@@ -12338,21 +12338,8 @@ $dbh->do(q| > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci > |); > >-my $mappings_yaml = C4::Context->config('intranetdir') . '/admin/searchengine/elasticsearch/mappings.yaml'; >-my $indexes = LoadFile( $mappings_yaml ); >- >-while ( my ( $index_name, $fields ) = each %$indexes ) { >- while ( my ( $field_name, $data ) = each %$fields ) { >- my $field_type = $data->{type}; >- my $field_label = $data->{label}; >- my $mappings = $data->{mappings}; >- my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type }, { key => 'name' }); >- for my $mapping ( @$mappings ) { >- my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} }); >- $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet}, suggestible => $mapping->{suggestible}, sort => $mapping->{sort} } ); >- } >- } >-} >+ # Insert default mappings >+ Koha::ElasticSearch->reset_elasticsearch_mappings; > > print "Upgrade to $DBversion done (Bug 12478 - Elasticsearch support for Koha)\n"; > SetVersion($DBversion); >diff --git a/installer/install.pl b/installer/install.pl >index cc67557..f46229b 100755 >--- a/installer/install.pl >+++ b/installer/install.pl >@@ -209,6 +209,8 @@ elsif ( $step && $step == 3 ) { > "fwklanguage" => $fwk_language, > "list" => $list > ); >+ use Koha::ElasticSearch; >+ Koha::ElasticSearch->reset_elasticsearch_mappings; > $template->param( "$op" => 1 ); > } > elsif ( $op && $op eq 'selectframeworks' ) { >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 16838
:
55909
|
55929
| 56135