From 5b3bb43d2a32549d1a523e54efb71f577b6389bd Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 18 Oct 2017 13:06:22 +0000 Subject: [PATCH] Bug 19482 - Add support for defining 'mandatory' mappings To test: 1 - Apply patch 2 - ./installer/data/mysql/updatedatabase.pl 3 - Clear all ES mappings form the db: DELETE FROM search_field; DELETE FROM search_marc_map; DELETE FROM search_marc_to_field; 4 - Reset ES mapping: /cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl?op=reset&i_know_what_i_am_doing=1 5 - issues should now be uneditable and not removable Signed-off-by: Nicolas Legrand --- Koha/SearchEngine/Elasticsearch.pm | 4 +- admin/searchengine/elasticsearch/mappings.pl | 1 + admin/searchengine/elasticsearch/mappings.yaml | 1 + .../admin/searchengine/elasticsearch/mappings.tt | 193 ++++++++++++--------- 4 files changed, 117 insertions(+), 82 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index d859a39..0980cd9 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -286,8 +286,10 @@ sub reset_elasticsearch_mappings { while ( my ( $field_name, $data ) = each %$fields ) { my $field_type = $data->{type}; my $field_label = $data->{label}; + my $field_mandatory = $data->{mandatory}; + warn $field_mandatory; my $mappings = $data->{mappings}; - my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type }, { key => 'name' }); + my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type, mandatory => $field_mandatory }, { key => 'name' }); for my $mapping ( @$mappings ) { my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} }); $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet} || 0, suggestible => $mapping->{suggestible} || 0, sort => $mapping->{sort} } ); diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl index 7d63002..3124a7f 100755 --- a/admin/searchengine/elasticsearch/mappings.pl +++ b/admin/searchengine/elasticsearch/mappings.pl @@ -123,6 +123,7 @@ for my $index_name (qw| biblios authorities |) { { search_field_name => $s->name, search_field_label => $s->label, search_field_type => $s->type, + search_field_mandatory => $s->mandatory, marc_field => $s->get_column('marc_field'), sort => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc" suggestible => $s->get_column('suggestible'), diff --git a/admin/searchengine/elasticsearch/mappings.yaml b/admin/searchengine/elasticsearch/mappings.yaml index 25a1cc7..826d3a3 100644 --- a/admin/searchengine/elasticsearch/mappings.yaml +++ b/admin/searchengine/elasticsearch/mappings.yaml @@ -1602,6 +1602,7 @@ biblios: sort: 1 suggestible: '' type: sum + mandatory: 1 itemnumber: label: itemnumber mappings: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt index 24327c5..c2b93dd 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt @@ -130,40 +130,49 @@ a.add, a.delete { [% FOREACH search_field IN all_search_fields %] + [% IF search_field.mandatory %] + [% SET is_readonly = "readonly" %] + [% ELSE %] + [% SET is_readonly = "" %] + [% END %] - + - + - + [% IF is_readonly %] + + [% ELSE %] + + [% END %] [% END %] @@ -185,59 +194,81 @@ a.add, a.delete { [% FOREACH mapping IN index.mappings %] - - - - + [% IF mapping.search_field_mandatory %] + + + + [% mapping.search_field_label %] - - - - - - - - - [% IF mapping.sort == 'undef' %]Undef[% ELSE %][% mapping.sort %][% END %] + + + [% IF mapping.facet == 1 %]Yes[% ELSE %]No[% END %] + + + [% IF mapping.suggestible == 1 %]Yes[% ELSE %]No[% END %] + + + + + + [% ELSE %] + + + + + [% mapping.search_field_label %] + + + + + + + + + + + + + + Delete + [% END %] - - - - - - Delete - - [% END %] + [% END %] -- 2.1.4