Lines 16-21
Link Here
|
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
|
|
19 |
use Scalar::Util qw(looks_like_number); |
19 |
use CGI; |
20 |
use CGI; |
20 |
use C4::Koha; |
21 |
use C4::Koha; |
21 |
use C4::Output; |
22 |
use C4::Output; |
Lines 24-29
use C4::Auth;
Link Here
|
24 |
use Koha::SearchEngine::Elasticsearch; |
25 |
use Koha::SearchEngine::Elasticsearch; |
25 |
use Koha::SearchMarcMaps; |
26 |
use Koha::SearchMarcMaps; |
26 |
use Koha::SearchFields; |
27 |
use Koha::SearchFields; |
|
|
28 |
use Koha::Caches; |
27 |
|
29 |
|
28 |
my $input = new CGI; |
30 |
my $input = new CGI; |
29 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
31 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
Lines 44-49
my $schema = $database->schema;
Link Here
|
44 |
|
46 |
|
45 |
my $marc_type = lc C4::Context->preference('marcflavour'); |
47 |
my $marc_type = lc C4::Context->preference('marcflavour'); |
46 |
|
48 |
|
|
|
49 |
my $cache = Koha::Caches->get_instance(); |
50 |
my $clear_cache = sub { |
51 |
$cache->clear_from_cache('elasticsearch_search_fields_staff_client'); |
52 |
$cache->clear_from_cache('elasticsearch_search_fields_opac'); |
53 |
}; |
54 |
|
47 |
if ( $op eq 'edit' ) { |
55 |
if ( $op eq 'edit' ) { |
48 |
|
56 |
|
49 |
$schema->storage->txn_begin; |
57 |
$schema->storage->txn_begin; |
Lines 51-62
if ( $op eq 'edit' ) {
Link Here
|
51 |
my @field_name = $input->param('search_field_name'); |
59 |
my @field_name = $input->param('search_field_name'); |
52 |
my @field_label = $input->param('search_field_label'); |
60 |
my @field_label = $input->param('search_field_label'); |
53 |
my @field_type = $input->param('search_field_type'); |
61 |
my @field_type = $input->param('search_field_type'); |
|
|
62 |
my @field_boost = $input->param('search_field_boost'); |
63 |
my @field_staff_client = $input->param('search_field_staff_client'); |
64 |
my @field_opac = $input->param('search_field_opac'); |
54 |
|
65 |
|
55 |
my @index_name = $input->param('mapping_index_name'); |
66 |
my @index_name = $input->param('mapping_index_name'); |
56 |
my @search_field_name = $input->param('mapping_search_field_name'); |
67 |
my @search_field_name = $input->param('mapping_search_field_name'); |
57 |
my @mapping_sort = $input->param('mapping_sort'); |
68 |
my @mapping_sort = $input->param('mapping_sort'); |
58 |
my @mapping_facet = $input->param('mapping_facet'); |
69 |
my @mapping_facet = $input->param('mapping_facet'); |
59 |
my @mapping_suggestible = $input->param('mapping_suggestible'); |
70 |
my @mapping_suggestible = $input->param('mapping_suggestible'); |
|
|
71 |
my @mapping_search = $input->param('mapping_search'); |
60 |
my @mapping_marc_field = $input->param('mapping_marc_field'); |
72 |
my @mapping_marc_field = $input->param('mapping_marc_field'); |
61 |
|
73 |
|
62 |
eval { |
74 |
eval { |
Lines 65-73
if ( $op eq 'edit' ) {
Link Here
|
65 |
my $field_name = $field_name[$i]; |
77 |
my $field_name = $field_name[$i]; |
66 |
my $field_label = $field_label[$i]; |
78 |
my $field_label = $field_label[$i]; |
67 |
my $field_type = $field_type[$i]; |
79 |
my $field_type = $field_type[$i]; |
|
|
80 |
my $field_boost = $field_boost[$i]; |
81 |
my $field_staff_client = $field_staff_client[$i]; |
82 |
my $field_opac = $field_opac[$i]; |
68 |
my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } ); |
83 |
my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } ); |
69 |
$search_field->label($field_label); |
84 |
$search_field->label($field_label); |
70 |
$search_field->type($field_type); |
85 |
$search_field->type($field_type); |
|
|
86 |
$search_field->boost($field_boost) if looks_like_number($field_boost); |
87 |
$search_field->staff_client($field_staff_client ? 1 : 0); |
88 |
$search_field->opac($field_opac ? 1 : 0); |
71 |
$search_field->store; |
89 |
$search_field->store; |
72 |
} |
90 |
} |
73 |
|
91 |
|
Lines 75-92
if ( $op eq 'edit' ) {
Link Here
|
75 |
|
93 |
|
76 |
for my $i ( 0 .. scalar(@index_name) - 1 ) { |
94 |
for my $i ( 0 .. scalar(@index_name) - 1 ) { |
77 |
my $index_name = $index_name[$i]; |
95 |
my $index_name = $index_name[$i]; |
78 |
my $search_field_name = $search_field_name[$i]; |
96 |
my $search_field_name = $search_field_name[$i]; |
79 |
my $mapping_marc_field = $mapping_marc_field[$i]; |
97 |
my $mapping_marc_field = $mapping_marc_field[$i]; |
80 |
my $mapping_facet = $mapping_facet[$i]; |
98 |
my $mapping_facet = $mapping_facet[$i]; |
81 |
my $mapping_suggestible = $mapping_suggestible[$i]; |
99 |
my $mapping_suggestible = $mapping_suggestible[$i]; |
82 |
my $mapping_sort = $mapping_sort[$i]; |
100 |
my $mapping_sort = $mapping_sort[$i] eq 'undef' ? undef : $mapping_sort[$i]; |
83 |
$mapping_sort = undef if $mapping_sort eq 'undef'; |
101 |
my $mapping_search = $mapping_search[$i]; |
84 |
|
102 |
|
85 |
my $search_field = Koha::SearchFields->find({ name => $search_field_name }, { key => 'name' }); |
103 |
my $search_field = Koha::SearchFields->find({ name => $search_field_name }, { key => 'name' }); |
86 |
# TODO Check mapping format |
104 |
# TODO Check mapping format |
87 |
my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $marc_type, marc_field => $mapping_marc_field }); |
105 |
my $marc_field = Koha::SearchMarcMaps->find_or_create({ |
88 |
$search_field->add_to_search_marc_maps($marc_field, { facet => $mapping_facet, suggestible => $mapping_suggestible, sort => $mapping_sort } ); |
106 |
index_name => $index_name, |
89 |
|
107 |
marc_type => $marc_type, |
|
|
108 |
marc_field => $mapping_marc_field |
109 |
}); |
110 |
$search_field->add_to_search_marc_maps($marc_field, { |
111 |
facet => $mapping_facet, |
112 |
suggestible => $mapping_suggestible, |
113 |
sort => $mapping_sort, |
114 |
search => $mapping_search, |
115 |
}); |
90 |
} |
116 |
} |
91 |
}; |
117 |
}; |
92 |
if ($@) { |
118 |
if ($@) { |
Lines 96-101
if ( $op eq 'edit' ) {
Link Here
|
96 |
push @messages, { type => 'message', code => 'success_on_update' }; |
122 |
push @messages, { type => 'message', code => 'success_on_update' }; |
97 |
$schema->storage->txn_commit; |
123 |
$schema->storage->txn_commit; |
98 |
} |
124 |
} |
|
|
125 |
$clear_cache->(); |
99 |
} |
126 |
} |
100 |
elsif( $op eq 'reset' ) { |
127 |
elsif( $op eq 'reset' ) { |
101 |
# TODO Move this feature to the interface |
128 |
# TODO Move this feature to the interface |
Lines 104-135
elsif( $op eq 'reset' ) {
Link Here
|
104 |
Koha::SearchMarcMaps->search->delete; |
131 |
Koha::SearchMarcMaps->search->delete; |
105 |
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; |
132 |
Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; |
106 |
} |
133 |
} |
|
|
134 |
$clear_cache->(); |
107 |
} |
135 |
} |
108 |
|
136 |
|
109 |
my @indexes; |
137 |
my @indexes; |
110 |
|
138 |
|
111 |
for my $index_name (qw| biblios authorities |) { |
139 |
for my $index_name (qw| biblios authorities |) { |
112 |
my $search_fields = Koha::SearchFields->search( |
140 |
my $search_fields = Koha::SearchFields->search( |
113 |
{ 'search_marc_map.index_name' => $index_name, 'search_marc_map.marc_type' => $marc_type, }, |
141 |
{ |
114 |
{ join => { search_marc_to_fields => 'search_marc_map' }, |
142 |
'search_marc_map.index_name' => $index_name, |
115 |
'+select' => [ 'search_marc_to_fields.facet', 'search_marc_to_fields.suggestible', 'search_marc_to_fields.sort', 'search_marc_map.marc_field' ], |
143 |
'search_marc_map.marc_type' => $marc_type, |
116 |
'+as' => [ 'facet', 'suggestible', 'sort', 'marc_field' ], |
144 |
}, |
|
|
145 |
{ |
146 |
join => { search_marc_to_fields => 'search_marc_map' }, |
147 |
'+select' => [ |
148 |
'search_marc_to_fields.facet', |
149 |
'search_marc_to_fields.suggestible', |
150 |
'search_marc_to_fields.sort', |
151 |
'search_marc_to_fields.search', |
152 |
'search_marc_map.marc_field', |
153 |
], |
154 |
'+as' => [ |
155 |
'facet', |
156 |
'suggestible', |
157 |
'sort', |
158 |
'search', |
159 |
'marc_field', |
160 |
], |
117 |
} |
161 |
} |
118 |
); |
162 |
); |
119 |
|
163 |
|
120 |
my @mappings; |
164 |
my @mappings; |
121 |
while ( my $s = $search_fields->next ) { |
165 |
while ( my $s = $search_fields->next ) { |
122 |
push @mappings, |
166 |
push @mappings, { |
123 |
{ search_field_name => $s->name, |
167 |
search_field_name => $s->name, |
124 |
search_field_label => $s->label, |
168 |
search_field_label => $s->label, |
125 |
search_field_type => $s->type, |
169 |
search_field_type => $s->type, |
126 |
marc_field => $s->get_column('marc_field'), |
170 |
marc_field => $s->get_column('marc_field'), |
127 |
sort => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc" |
171 |
sort => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc" |
128 |
suggestible => $s->get_column('suggestible'), |
172 |
suggestible => $s->get_column('suggestible'), |
129 |
facet => $s->get_column('facet'), |
173 |
facet => $s->get_column('facet'), |
130 |
}; |
174 |
search => $s->get_column('search'), |
|
|
175 |
}; |
131 |
} |
176 |
} |
132 |
|
|
|
133 |
push @indexes, { index_name => $index_name, mappings => \@mappings }; |
177 |
push @indexes, { index_name => $index_name, mappings => \@mappings }; |
134 |
} |
178 |
} |
135 |
|
179 |
|