Lines 17-22
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use CGI; |
19 |
use CGI; |
|
|
20 |
use List::Util qw( first ); |
20 |
use C4::Koha; |
21 |
use C4::Koha; |
21 |
use C4::Output; |
22 |
use C4::Output; |
22 |
use C4::Auth; |
23 |
use C4::Auth; |
Lines 48-63
if ( $op eq 'edit' ) {
Link Here
|
48 |
|
49 |
|
49 |
$schema->storage->txn_begin; |
50 |
$schema->storage->txn_begin; |
50 |
|
51 |
|
51 |
my @field_name = $input->param('search_field_name'); |
52 |
my @field_name = $input->multi_param('search_field_name'); |
52 |
my @field_label = $input->param('search_field_label'); |
53 |
my @field_label = $input->multi_param('search_field_label'); |
53 |
my @field_type = $input->param('search_field_type'); |
54 |
my @field_type = $input->multi_param('search_field_type'); |
54 |
|
55 |
|
55 |
my @index_name = $input->param('mapping_index_name'); |
56 |
my @index_name = $input->multi_param('mapping_index_name'); |
56 |
my @search_field_name = $input->param('mapping_search_field_name'); |
57 |
my @search_field_name = $input->multi_param('mapping_search_field_name'); |
57 |
my @mapping_sort = $input->param('mapping_sort'); |
58 |
my @mapping_sort = $input->multi_param('mapping_sort'); |
58 |
my @mapping_facet = $input->param('mapping_facet'); |
59 |
my @mapping_facet = $input->multi_param('mapping_facet'); |
59 |
my @mapping_suggestible = $input->param('mapping_suggestible'); |
60 |
my @mapping_suggestible = $input->multi_param('mapping_suggestible'); |
60 |
my @mapping_marc_field = $input->param('mapping_marc_field'); |
61 |
my @mapping_marc_field = $input->multi_param('mapping_marc_field'); |
|
|
62 |
my @faceted_field_names = $input->multi_param('display_facet'); |
61 |
|
63 |
|
62 |
eval { |
64 |
eval { |
63 |
|
65 |
|
Lines 68-77
if ( $op eq 'edit' ) {
Link Here
|
68 |
my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } ); |
70 |
my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } ); |
69 |
$search_field->label($field_label); |
71 |
$search_field->label($field_label); |
70 |
$search_field->type($field_type); |
72 |
$search_field->type($field_type); |
|
|
73 |
my $facet_order = first { $faceted_field_names[$_] eq $field_name } 0 .. $#faceted_field_names; |
74 |
$search_field->facet_order(defined $facet_order ? $facet_order + 1 : undef); |
71 |
$search_field->store; |
75 |
$search_field->store; |
72 |
} |
76 |
} |
73 |
|
77 |
|
74 |
Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete; |
78 |
Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete; |
|
|
79 |
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields(); |
80 |
my @facetable_field_names = map { $_->name } @facetable_fields; |
75 |
|
81 |
|
76 |
for my $i ( 0 .. scalar(@index_name) - 1 ) { |
82 |
for my $i ( 0 .. scalar(@index_name) - 1 ) { |
77 |
my $index_name = $index_name[$i]; |
83 |
my $index_name = $index_name[$i]; |
Lines 81-86
if ( $op eq 'edit' ) {
Link Here
|
81 |
my $mapping_suggestible = $mapping_suggestible[$i]; |
87 |
my $mapping_suggestible = $mapping_suggestible[$i]; |
82 |
my $mapping_sort = $mapping_sort[$i]; |
88 |
my $mapping_sort = $mapping_sort[$i]; |
83 |
$mapping_sort = undef if $mapping_sort eq 'undef'; |
89 |
$mapping_sort = undef if $mapping_sort eq 'undef'; |
|
|
90 |
$mapping_facet = ( grep {/^$search_field_name$/} @facetable_field_names ) ? $mapping_facet : 0; |
84 |
|
91 |
|
85 |
my $search_field = Koha::SearchFields->find({ name => $search_field_name }, { key => 'name' }); |
92 |
my $search_field = Koha::SearchFields->find({ name => $search_field_name }, { key => 'name' }); |
86 |
# TODO Check mapping format |
93 |
# TODO Check mapping format |
Lines 118-132
for my $index_name (qw| biblios authorities |) {
Link Here
|
118 |
); |
125 |
); |
119 |
|
126 |
|
120 |
my @mappings; |
127 |
my @mappings; |
|
|
128 |
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields(); |
129 |
my @facetable_field_names = map { $_->name } @facetable_fields; |
130 |
|
121 |
while ( my $s = $search_fields->next ) { |
131 |
while ( my $s = $search_fields->next ) { |
|
|
132 |
my $name = $s->name; |
122 |
push @mappings, |
133 |
push @mappings, |
123 |
{ search_field_name => $s->name, |
134 |
{ search_field_name => $name, |
124 |
search_field_label => $s->label, |
135 |
search_field_label => $s->label, |
125 |
search_field_type => $s->type, |
136 |
search_field_type => $s->type, |
126 |
marc_field => $s->get_column('marc_field'), |
137 |
marc_field => $s->get_column('marc_field'), |
127 |
sort => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc" |
138 |
sort => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc" |
128 |
suggestible => $s->get_column('suggestible'), |
139 |
suggestible => $s->get_column('suggestible'), |
129 |
facet => $s->get_column('facet'), |
140 |
facet => $s->get_column('facet'), |
|
|
141 |
is_facetable => ( grep {/^$name$/} @facetable_field_names ) ? 1 : 0, |
130 |
}; |
142 |
}; |
131 |
} |
143 |
} |
132 |
|
144 |
|
Lines 135-143
for my $index_name (qw| biblios authorities |) {
Link Here
|
135 |
|
147 |
|
136 |
my $search_fields = $schema->resultset('SearchField')->search; |
148 |
my $search_fields = $schema->resultset('SearchField')->search; |
137 |
my @all_search_fields = $search_fields->search( {}, { order_by => ['name'] } ); |
149 |
my @all_search_fields = $search_fields->search( {}, { order_by => ['name'] } ); |
|
|
150 |
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields(); |
138 |
$template->param( |
151 |
$template->param( |
139 |
indexes => \@indexes, |
152 |
indexes => \@indexes, |
140 |
all_search_fields => \@all_search_fields, |
153 |
all_search_fields => \@all_search_fields, |
|
|
154 |
facetable_fields => \@facetable_fields, |
141 |
messages => \@messages, |
155 |
messages => \@messages, |
142 |
); |
156 |
); |
143 |
|
157 |
|