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

(-)a/Koha/SearchEngine/Elasticsearch.pm (+2 lines)
Lines 209-214 sub get_elasticsearch_mappings { Link Here
209
                    $es_type = 'stdno';
209
                    $es_type = 'stdno';
210
                } elsif ($type eq 'year') {
210
                } elsif ($type eq 'year') {
211
                    $es_type = 'year';
211
                    $es_type = 'year';
212
                } elsif ($type eq 'callnumber') {
213
                    $es_type = 'cn_sort';
212
                }
214
                }
213
215
214
                if ($search) {
216
                if ($search) {
(-)a/admin/searchengine/elasticsearch/field_config.yaml (+4 lines)
Lines 71-73 sort: Link Here
71
    type: icu_collation_keyword
71
    type: icu_collation_keyword
72
    index: false
72
    index: false
73
    numeric: true
73
    numeric: true
74
  cn_sort:
75
    type: icu_collation_keyword
76
    index: false
77
    numeric: false
(-)a/admin/searchengine/elasticsearch/mappings.yaml (-1 / +1 lines)
Lines 1167-1173 biblios: Link Here
1167
        marc_type: marc21
1167
        marc_type: marc21
1168
        sort: 1
1168
        sort: 1
1169
        suggestible: ''
1169
        suggestible: ''
1170
    type: ''
1170
    type: 'callnumber'
1171
  cn-suffix:
1171
  cn-suffix:
1172
    label: cn-suffix
1172
    label: cn-suffix
1173
    mappings:
1173
    mappings:
(-)a/installer/data/mysql/atomicupdate/bug_29632.pl (+16 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "29632",
5
    description => "Add callnumber type to allow sorting",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        $dbh->do(q{
10
            ALTER TABLE `search_field` MODIFY COLUMN `type`
11
            enum('','string','date','number','boolean','sum','isbn','stdno','year','callnumber') NOT NULL
12
            COMMENT 'what type of data this holds, relevant when storing it in the search engine'
13
        });
14
        say $out "Add callnumber to search_field type enum";
15
    },
16
};
(-)a/installer/data/mysql/kohastructure.sql (-1 / +1 lines)
Lines 4483-4489 CREATE TABLE `search_field` ( Link Here
4483
  `id` int(11) NOT NULL AUTO_INCREMENT,
4483
  `id` int(11) NOT NULL AUTO_INCREMENT,
4484
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the name of the field as it will be stored in the search engine',
4484
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the name of the field as it will be stored in the search engine',
4485
  `label` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the human readable name of the field, for display',
4485
  `label` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'the human readable name of the field, for display',
4486
  `type` enum('','string','date','number','boolean','sum','isbn','stdno','year') COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'what type of data this holds, relevant when storing it in the search engine',
4486
  `type` enum('','string','date','number','boolean','sum','isbn','stdno','year','callnumber') COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'what type of data this holds, relevant when storing it in the search engine',
4487
  `weight` decimal(5,2) DEFAULT NULL,
4487
  `weight` decimal(5,2) DEFAULT NULL,
4488
  `facet_order` tinyint(4) DEFAULT NULL COMMENT 'the order place of the field in facet list if faceted',
4488
  `facet_order` tinyint(4) DEFAULT NULL COMMENT 'the order place of the field in facet list if faceted',
4489
  `staff_client` tinyint(1) NOT NULL DEFAULT 1,
4489
  `staff_client` tinyint(1) NOT NULL DEFAULT 1,
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (+5 lines)
Lines 210-215 a.add, a.delete { Link Here
210
                              [% ELSE %]
210
                              [% ELSE %]
211
                                <option value="stdno">Std. Number</option>
211
                                <option value="stdno">Std. Number</option>
212
                              [% END %]
212
                              [% END %]
213
                              [% IF search_field.type == "callnumber" %]
214
                                <option value="callnumber" selected="selected">Call Number</option>
215
                              [% ELSE %]
216
                                <option value="callnumber">Call Number</option>
217
                              [% END %]
213
                            </select>
218
                            </select>
214
                      </td>
219
                      </td>
215
                        <td data-order="[% search_field.weight | html %]">
220
                        <td data-order="[% search_field.weight | html %]">
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t (-5 / +47 lines)
Lines 127-140 subtest 'get_elasticsearch_settings() tests' => sub { Link Here
127
127
128
subtest 'get_elasticsearch_mappings() tests' => sub {
128
subtest 'get_elasticsearch_mappings() tests' => sub {
129
129
130
    plan tests => 1;
130
    plan tests => 3;
131
131
132
    my $mappings;
132
    my $mappings;
133
133
134
    # test reading mappings
134
    my @mappings = (
135
    my $es = Koha::SearchEngine::Elasticsearch->new( {index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX} );
135
        {
136
    $mappings = $es->get_elasticsearch_mappings();
136
            name => 'cn-sort',
137
            type => 'callnumber',
138
            facet => 0,
139
            suggestible => 0,
140
            searchable => 1,
141
            sort => 1,
142
            marc_type => 'marc21',
143
            marc_field => '001',
144
        },
145
        {
146
            name => 'isbn',
147
            type => 'string',
148
            facet => 0,
149
            suggestible => 0,
150
            searchable => 1,
151
            sort => 1,
152
            marc_type => 'marc21',
153
            marc_field => '020a',
154
        },
155
    );
156
    my $search_engine_module = Test::MockModule->new('Koha::SearchEngine::Elasticsearch');
157
    $search_engine_module->mock('_foreach_mapping', sub {
158
        my ($self, $sub) = @_;
159
160
        foreach my $map (@mappings) {
161
            $sub->(
162
                $map->{name},
163
                $map->{type},
164
                $map->{facet},
165
                $map->{suggestible},
166
                $map->{sort},
167
                $map->{searchable},
168
                $map->{marc_type},
169
                $map->{marc_field}
170
            );
171
        }
172
    });
173
174
    my $search_engine_elasticsearch = Koha::SearchEngine::Elasticsearch::Search->new({ index => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX });
175
    $mappings = $search_engine_elasticsearch->get_elasticsearch_mappings();
176
177
    is( $mappings->{properties}{"cn-sort__sort"}{index}, 'false', 'Field mappings parsed correctly for sort for callnumber type' );
178
    is( $mappings->{properties}{"cn-sort__sort"}{numeric}, 'false', 'Field mappings parsed correctly for sort for callnumber type' );
137
    is( $mappings->{properties}{isbn__sort}{index}, 'false', 'Field mappings parsed correctly' );
179
    is( $mappings->{properties}{isbn__sort}{index}, 'false', 'Field mappings parsed correctly' );
180
138
};
181
};
139
182
140
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
183
subtest 'Koha::SearchEngine::Elasticsearch::marc_records_to_documents () tests' => sub {
141
- 

Return to bug 29632