View | Details | Raw Unified | Return to bug 16838
Collapse All | Expand All

(-)a/Koha/ElasticSearch.pm (+21 lines)
Lines 22-32 use base qw(Class::Accessor); Link Here
22
use C4::Context;
22
use C4::Context;
23
23
24
use Koha::Database;
24
use Koha::Database;
25
use Koha::SearchFields;
26
use Koha::SearchMarcMaps;
25
27
26
use Carp;
28
use Carp;
27
use JSON;
29
use JSON;
28
use Modern::Perl;
30
use Modern::Perl;
29
use Readonly;
31
use Readonly;
32
use YAML::Syck;
30
33
31
use Data::Dumper;    # TODO remove
34
use Data::Dumper;    # TODO remove
32
35
Lines 250-255 sub get_elasticsearch_mappings { Link Here
250
    return $mappings;
253
    return $mappings;
251
}
254
}
252
255
256
sub reset_elasticsearch_mappings {
257
    my $mappings_yaml = C4::Context->config('intranetdir') . '/admin/searchengine/elasticsearch/mappings.yaml';
258
    my $indexes = LoadFile( $mappings_yaml );
259
260
    while ( my ( $index_name, $fields ) = each %$indexes ) {
261
        while ( my ( $field_name, $data ) = each %$fields ) {
262
            my $field_type = $data->{type};
263
            my $field_label = $data->{label};
264
            my $mappings = $data->{mappings};
265
            my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type }, { key => 'name' });
266
            for my $mapping ( @$mappings ) {
267
                my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} });
268
                $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet}, suggestible => $mapping->{suggestible}, sort => $mapping->{sort} } );
269
            }
270
        }
271
    }
272
}
273
253
# This overrides the accessor provided by Class::Accessor so that if
274
# This overrides the accessor provided by Class::Accessor so that if
254
# sort_fields isn't set, then it'll generate it.
275
# sort_fields isn't set, then it'll generate it.
255
sub sort_fields {
276
sub sort_fields {
(-)a/installer/data/mysql/updatedatabase.pl (-16 / +3 lines)
Lines 12265-12273 if ( $column_has_been_used ) { Link Here
12265
12265
12266
$DBversion = "3.23.00.050";
12266
$DBversion = "3.23.00.050";
12267
if ( CheckVersion($DBversion) ) {
12267
if ( CheckVersion($DBversion) ) {
12268
    use YAML::Syck;
12269
    use Koha::SearchMarcMaps;
12268
    use Koha::SearchMarcMaps;
12270
    use Koha::SearchFields;
12269
    use Koha::SearchFields;
12270
    use Koha::ElasticSearch;
12271
12271
12272
    $dbh->do(q|INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
12272
    $dbh->do(q|INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type)
12273
                    VALUES('SearchEngine','Zebra','Choose Search Engine','','Choice')|);
12273
                    VALUES('SearchEngine','Zebra','Choose Search Engine','','Choice')|);
Lines 12329-12349 $dbh->do(q| Link Here
12329
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
12329
            ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
12330
        |);
12330
        |);
12331
12331
12332
my $mappings_yaml = C4::Context->config('intranetdir') . '/admin/searchengine/elasticsearch/mappings.yaml';
12332
        # Insert default mappings
12333
my $indexes = LoadFile( $mappings_yaml );
12333
        Koha::ElasticSearch->reset_elasticsearch_mappings;
12334
12335
while ( my ( $index_name, $fields ) = each %$indexes ) {
12336
        while ( my ( $field_name, $data ) = each %$fields ) {
12337
            my $field_type = $data->{type};
12338
            my $field_label = $data->{label};
12339
            my $mappings = $data->{mappings};
12340
            my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type }, { key => 'name' });
12341
            for my $mapping ( @$mappings ) {
12342
                my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} });
12343
                $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet}, suggestible => $mapping->{suggestible}, sort => $mapping->{sort} } );
12344
            }
12345
        }
12346
}
12347
12334
12348
print "Upgrade to $DBversion done (Bug 12478 - Elasticsearch support for Koha)\n";
12335
print "Upgrade to $DBversion done (Bug 12478 - Elasticsearch support for Koha)\n";
12349
    SetVersion($DBversion);
12336
    SetVersion($DBversion);
(-)a/installer/install.pl (-1 / +2 lines)
Lines 209-214 elsif ( $step && $step == 3 ) { Link Here
209
            "fwklanguage" => $fwk_language,
209
            "fwklanguage" => $fwk_language,
210
            "list"        => $list
210
            "list"        => $list
211
        );
211
        );
212
        use Koha::ElasticSearch;
213
        Koha::ElasticSearch->reset_elasticsearch_mappings;
212
        $template->param( "$op" => 1 );
214
        $template->param( "$op" => 1 );
213
    }
215
    }
214
    elsif ( $op && $op eq 'selectframeworks' ) {
216
    elsif ( $op && $op eq 'selectframeworks' ) {
215
- 

Return to bug 16838