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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-16 / +5 lines)
Lines 284-306 sub reset_elasticsearch_mappings { Link Here
284
284
285
    while ( my ( $index_name, $fields ) = each %$indexes ) {
285
    while ( my ( $index_name, $fields ) = each %$indexes ) {
286
        while ( my ( $field_name, $data ) = each %$fields ) {
286
        while ( my ( $field_name, $data ) = each %$fields ) {
287
            my $field_type = $data->{type};
287
            my %sf_params = map { $_ => $data->{$_} } grep { exists $data->{$_} } qw/ type label weight facet_order /;
288
            my $field_label = $data->{label};
288
            $sf_params{name} = $field_name;
289
290
            my $search_field = Koha::SearchFields->find_or_create( \%sf_params, { key => 'name' } );
291
289
            my $mappings = $data->{mappings};
292
            my $mappings = $data->{mappings};
290
            my $facet_order = $data->{facet_order};
291
            my $search_field = Koha::SearchFields->find_or_create({
292
                name  => $field_name,
293
                label => $field_label,
294
                type  => $field_type,
295
            },
296
            {
297
                key => 'name'
298
            });
299
            $search_field->update(
300
                {
301
                    facet_order => $facet_order
302
                }
303
            );
304
            for my $mapping ( @$mappings ) {
293
            for my $mapping ( @$mappings ) {
305
                my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} });
294
                my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} });
306
                $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet} || 0, suggestible => $mapping->{suggestible} || 0, sort => $mapping->{sort} } );
295
                $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet} || 0, suggestible => $mapping->{suggestible} || 0, sort => $mapping->{sort} } );
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/Reset.t (-1 / +66 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 4;
21
use Test::MockModule;
22
23
use Koha::Database;
24
25
my $indexes = {
26
    'authorities' => {
27
        'Match' => {
28
            'label' => 'Match',
29
            'type' => '',
30
            'weight' => 15,
31
            'mappings' => []
32
        }
33
    },
34
    'biblios' => {
35
        'title' => {
36
            'label' => 'title',
37
            'type' => '',
38
            'weight' => 20,
39
            'mapping' => []
40
        }
41
    }
42
};
43
44
my $yaml = Test::MockModule->new('YAML::Syck');
45
$yaml->mock( 'LoadFile', sub { return $indexes; } );
46
47
use_ok('Koha::SearchEngine::Elasticsearch');
48
49
my $schema = Koha::Database->new->schema;
50
51
Koha::SearchFields->search->delete;
52
Koha::SearchMarcMaps->search->delete;
53
$schema->resultset('SearchMarcToField')->search->delete;
54
55
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings;
56
57
my $search_fields = Koha::SearchFields->search({});
58
is($search_fields->count, 2, 'There is 2 search fields after reset');
59
60
my $match_sf = Koha::SearchFields->search({ name => 'Match' })->next;
61
is($match_sf->weight, '15.00', 'Match search field is weighted with 15');
62
63
my $title_sf = Koha::SearchFields->search({ name => 'title' })->next;
64
is($title_sf->weight, '20.00', 'Title search field is weighted with 20');
65
66
$schema->storage->txn_begin;

Return to bug 23078