Lines 18-23
Link Here
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
use CGI; |
19 |
use CGI; |
20 |
use Scalar::Util qw(looks_like_number); |
20 |
use Scalar::Util qw(looks_like_number); |
|
|
21 |
use List::Util qw( first ); |
21 |
use C4::Koha; |
22 |
use C4::Koha; |
22 |
use C4::Output; |
23 |
use C4::Output; |
23 |
use C4::Auth; |
24 |
use C4::Auth; |
Lines 71-87
if ( $op eq 'edit' ) {
Link Here
|
71 |
|
72 |
|
72 |
$schema->storage->txn_begin; |
73 |
$schema->storage->txn_begin; |
73 |
|
74 |
|
74 |
my @field_name = $input->param('search_field_name'); |
75 |
my @field_name = $input->multi_param('search_field_name'); |
75 |
my @field_label = $input->param('search_field_label'); |
76 |
my @field_label = $input->multi_param('search_field_label'); |
76 |
my @field_type = $input->param('search_field_type'); |
77 |
my @field_type = $input->multi_param('search_field_type'); |
77 |
my @field_weight = $input->param('search_field_weight'); |
78 |
my @field_weight = $input->multi_param('search_field_weight'); |
78 |
|
79 |
|
79 |
my @index_name = $input->param('mapping_index_name'); |
80 |
my @index_name = $input->multi_param('mapping_index_name'); |
80 |
my @search_field_name = $input->param('mapping_search_field_name'); |
81 |
my @search_field_name = $input->multi_param('mapping_search_field_name'); |
81 |
my @mapping_sort = $input->param('mapping_sort'); |
82 |
my @mapping_sort = $input->multi_param('mapping_sort'); |
82 |
my @mapping_facet = $input->param('mapping_facet'); |
83 |
my @mapping_facet = $input->multi_param('mapping_facet'); |
83 |
my @mapping_suggestible = $input->param('mapping_suggestible'); |
84 |
my @mapping_suggestible = $input->multi_param('mapping_suggestible'); |
84 |
my @mapping_marc_field = $input->param('mapping_marc_field'); |
85 |
my @mapping_marc_field = $input->multi_param('mapping_marc_field'); |
|
|
86 |
my @faceted_field_names = $input->multi_param('display_facet'); |
85 |
|
87 |
|
86 |
eval { |
88 |
eval { |
87 |
|
89 |
|
Lines 105-114
if ( $op eq 'edit' ) {
Link Here
|
105 |
$search_field->weight($field_weight); |
107 |
$search_field->weight($field_weight); |
106 |
} |
108 |
} |
107 |
|
109 |
|
|
|
110 |
my $facet_order = first { $faceted_field_names[$_] eq $field_name } 0 .. $#faceted_field_names; |
111 |
$search_field->facet_order(defined $facet_order ? $facet_order + 1 : undef); |
108 |
$search_field->store; |
112 |
$search_field->store; |
109 |
} |
113 |
} |
110 |
|
114 |
|
111 |
Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete; |
115 |
Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete; |
|
|
116 |
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields(); |
117 |
my @facetable_field_names = map { $_->name } @facetable_fields; |
112 |
|
118 |
|
113 |
for my $i ( 0 .. scalar(@index_name) - 1 ) { |
119 |
for my $i ( 0 .. scalar(@index_name) - 1 ) { |
114 |
my $index_name = $index_name[$i]; |
120 |
my $index_name = $index_name[$i]; |
Lines 118-123
if ( $op eq 'edit' ) {
Link Here
|
118 |
my $mapping_suggestible = $mapping_suggestible[$i]; |
124 |
my $mapping_suggestible = $mapping_suggestible[$i]; |
119 |
my $mapping_sort = $mapping_sort[$i]; |
125 |
my $mapping_sort = $mapping_sort[$i]; |
120 |
$mapping_sort = undef if $mapping_sort eq 'undef'; |
126 |
$mapping_sort = undef if $mapping_sort eq 'undef'; |
|
|
127 |
$mapping_facet = ( grep {/^$search_field_name$/} @facetable_field_names ) ? $mapping_facet : 0; |
121 |
|
128 |
|
122 |
my $search_field = Koha::SearchFields->find({ name => $search_field_name }, { key => 'name' }); |
129 |
my $search_field = Koha::SearchFields->find({ name => $search_field_name }, { key => 'name' }); |
123 |
# TODO Check mapping format |
130 |
# TODO Check mapping format |
Lines 180-194
for my $index_name (@index_names) {
Link Here
|
180 |
); |
187 |
); |
181 |
|
188 |
|
182 |
my @mappings; |
189 |
my @mappings; |
|
|
190 |
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields(); |
191 |
my @facetable_field_names = map { $_->name } @facetable_fields; |
192 |
|
183 |
while ( my $s = $search_fields->next ) { |
193 |
while ( my $s = $search_fields->next ) { |
|
|
194 |
my $name = $s->name; |
184 |
push @mappings, |
195 |
push @mappings, |
185 |
{ search_field_name => $s->name, |
196 |
{ search_field_name => $name, |
186 |
search_field_label => $s->label, |
197 |
search_field_label => $s->label, |
187 |
search_field_type => $s->type, |
198 |
search_field_type => $s->type, |
188 |
marc_field => $s->get_column('marc_field'), |
199 |
marc_field => $s->get_column('marc_field'), |
189 |
sort => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc" |
200 |
sort => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc" |
190 |
suggestible => $s->get_column('suggestible'), |
201 |
suggestible => $s->get_column('suggestible'), |
191 |
facet => $s->get_column('facet'), |
202 |
facet => $s->get_column('facet'), |
|
|
203 |
is_facetable => ( grep {/^$name$/} @facetable_field_names ) ? 1 : 0, |
192 |
}; |
204 |
}; |
193 |
} |
205 |
} |
194 |
|
206 |
|
Lines 203-211
while ( my $search_field = $search_fields->next ) {
Link Here
|
203 |
push @all_search_fields, $search_field_unblessed; |
215 |
push @all_search_fields, $search_field_unblessed; |
204 |
} |
216 |
} |
205 |
|
217 |
|
|
|
218 |
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields(); |
206 |
$template->param( |
219 |
$template->param( |
207 |
indexes => \@indexes, |
220 |
indexes => \@indexes, |
208 |
all_search_fields => \@all_search_fields, |
221 |
all_search_fields => \@all_search_fields, |
|
|
222 |
facetable_fields => \@facetable_fields, |
209 |
messages => \@messages, |
223 |
messages => \@messages, |
210 |
); |
224 |
); |
211 |
|
225 |
|