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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-1 / +25 lines)
Lines 285-291 sub reset_elasticsearch_mappings { Link Here
285
            my $field_type = $data->{type};
285
            my $field_type = $data->{type};
286
            my $field_label = $data->{label};
286
            my $field_label = $data->{label};
287
            my $mappings = $data->{mappings};
287
            my $mappings = $data->{mappings};
288
            my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type }, { key => 'name' });
288
            my $facet_order = $data->{facet_order};
289
            my $search_field = Koha::SearchFields->find_or_create({ name => $field_name });
290
            $search_field->update(
291
                {
292
                    label       => $field_label,
293
                    type        => $field_type,
294
                    facet_order => $facet_order
295
                }
296
            );
289
            for my $mapping ( @$mappings ) {
297
            for my $mapping ( @$mappings ) {
290
                my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} });
298
                my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} });
291
                $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet} || 0, suggestible => $mapping->{suggestible} || 0, sort => $mapping->{sort} } );
299
                $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet} || 0, suggestible => $mapping->{suggestible} || 0, sort => $mapping->{sort} } );
Lines 965-970 sub _read_configuration { Link Here
965
    return $configuration;
973
    return $configuration;
966
}
974
}
967
975
976
sub get_facetable_fields {
977
    my ($self) = @_;
978
979
    # These should correspond to the ES field names, as opposed to the CCL
980
    # things that zebra uses.
981
    my @search_field_names = qw( author itype location su-geo se subject ccode holdingbranch homebranch );
982
    my @faceted_fields = Koha::SearchFields->search(
983
        { name => { -in => \@search_field_names }, facet_order => { '!=' => undef } }, { order_by => ['facet_order'] }
984
    );
985
    my @not_faceted_fields = Koha::SearchFields->search(
986
        { name => { -in => \@search_field_names }, facet_order => undef }, { order_by => ['facet_order'] }
987
    );
988
    # This could certainly be improved
989
    return ( @faceted_fields, @not_faceted_fields );
990
}
991
968
1;
992
1;
969
993
970
__END__
994
__END__
(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (-12 / +18 lines)
Lines 436-453 sub _convert_facets { Link Here
436
436
437
    # These should correspond to the ES field names, as opposed to the CCL
437
    # These should correspond to the ES field names, as opposed to the CCL
438
    # things that zebra uses.
438
    # things that zebra uses.
439
    # TODO let the library define the order using the interface.
439
    my %type_to_label;
440
    my %type_to_label = (
440
    my %label = (
441
        author => { order => 1, label => 'Authors', },
441
        author         => 'Authors',
442
        itype => { order => 2, label => 'ItemTypes', },
442
        itype          => 'ItemTypes',
443
        location => { order => 3, label => 'Location', },
443
        location       => 'Location',
444
        'su-geo' => { order => 4, label => 'Places', },
444
        'su-geo'       => 'Places',
445
        'title-series' => { order => 5, label => 'Series', },
445
        'title-series' => 'Series',
446
        subject => { order => 6, label => 'Topics', },
446
        subject        => 'Topics',
447
        ccode => { order => 7, label => 'CollectionCodes',},
447
        ccode          => 'CollectionCodes',
448
        holdingbranch => { order => 8, label => 'HoldingLibrary' },
448
        holdingbranch  => 'HoldingLibrary',
449
        homebranch => { order => 9, label => 'HomeLibrary' }
449
        homebranch     => 'HomeLibrary',
450
    );
450
    );
451
    my @facetable_fields =
452
      Koha::SearchEngine::Elasticsearch->get_facetable_fields;
453
    for my $f (@facetable_fields) {
454
        next unless defined $f->facet_order;
455
        $type_to_label{ $f->name } =
456
          { order => $f->facet_order, label => $label{ $f->name } };
457
    }
451
458
452
    # We also have some special cases, e.g. itypes that need to show the
459
    # We also have some special cases, e.g. itypes that need to show the
453
    # value rather than the code.
460
    # value rather than the code.
Lines 505-509 sub _convert_facets { Link Here
505
    return \@facets;
512
    return \@facets;
506
}
513
}
507
514
508
509
1;
515
1;
(-)a/admin/searchengine/elasticsearch/mappings.pl (-11 / +25 lines)
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
(-)a/admin/searchengine/elasticsearch/mappings.yaml (+8 lines)
Lines 1265-1270 biblios: Link Here
1265
        sort: ~
1265
        sort: ~
1266
        suggestible: 0
1266
        suggestible: 0
1267
    type: string
1267
    type: string
1268
    facet_order: 1
1268
  author-in-order:
1269
  author-in-order:
1269
    label: author-in-order
1270
    label: author-in-order
1270
    mappings:
1271
    mappings:
Lines 1493-1498 biblios: Link Here
1493
        sort: ~
1494
        sort: ~
1494
        suggestible: ''
1495
        suggestible: ''
1495
    type: ''
1496
    type: ''
1497
    facet_order: 7
1496
  classification-source:
1498
  classification-source:
1497
    label: classification-source
1499
    label: classification-source
1498
    mappings:
1500
    mappings:
Lines 1980-1985 biblios: Link Here
1980
        sort: 0
1982
        sort: 0
1981
        suggestible: ''
1983
        suggestible: ''
1982
    type: string
1984
    type: string
1985
    facet_order: 8
1983
  homebranch:
1986
  homebranch:
1984
    label: homelibrary
1987
    label: homelibrary
1985
    mappings:
1988
    mappings:
Lines 1999-2004 biblios: Link Here
1999
        sort: 0
2002
        sort: 0
2000
        suggestible: ''
2003
        suggestible: ''
2001
    type: string
2004
    type: string
2005
    facet_order: 9
2002
  host-item:
2006
  host-item:
2003
    label: host-item
2007
    label: host-item
2004
    mappings:
2008
    mappings:
Lines 2273-2278 biblios: Link Here
2273
        sort: ~
2277
        sort: ~
2274
        suggestible: ''
2278
        suggestible: ''
2275
    type: string
2279
    type: string
2280
    facet_order: 2
2276
  koha-auth-number:
2281
  koha-auth-number:
2277
    label: koha-auth-number
2282
    label: koha-auth-number
2278
    mappings:
2283
    mappings:
Lines 2690-2695 biblios: Link Here
2690
        sort: 0
2695
        sort: 0
2691
        suggestible: ''
2696
        suggestible: ''
2692
    type: ''
2697
    type: ''
2698
    facet_order: 3
2693
  lost:
2699
  lost:
2694
    label: lost
2700
    label: lost
2695
    mappings:
2701
    mappings:
Lines 3624-3629 biblios: Link Here
3624
        sort: ~
3630
        sort: ~
3625
        suggestible: '1'
3631
        suggestible: '1'
3626
    type: string
3632
    type: string
3633
    facet_order: 6
3627
  subject-name-personal:
3634
  subject-name-personal:
3628
    label: subject-name-personal
3635
    label: subject-name-personal
3629
    mappings:
3636
    mappings:
Lines 4305-4310 biblios: Link Here
4305
        sort: ~
4312
        sort: ~
4306
        suggestible: ''
4313
        suggestible: ''
4307
    type: string
4314
    type: string
4315
    facet_order: 5
4308
  title-uniform:
4316
  title-uniform:
4309
    label: title-uniform
4317
    label: title-uniform
4310
    mappings:
4318
    mappings:
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-10 / +62 lines)
Lines 53-58 Link Here
53
                } );
53
                } );
54
            }
54
            }
55
        });
55
        });
56
        $("#facet_biblios > table").tableDnD( {
57
            onDragClass: "dragClass",
58
        } );
56
    });
59
    });
57
</script>
60
</script>
58
<style>
61
<style>
Lines 260-274 a.add, a.delete { Link Here
260
                              </select>
263
                              </select>
261
                            </td>
264
                            </td>
262
                            <td>
265
                            <td>
263
                              <select name="mapping_facet">
266
                              [% IF mapping.is_facetable %]
264
                                [% IF mapping.facet %]
267
                                <select name="mapping_facet">
265
                                  <option value="0">No</option>
268
                                  [% IF mapping.facet %]
266
                                  <option value="1" selected="selected">Yes</option>
269
                                    <option value="0">No</option>
267
                                [% ELSE %]
270
                                    <option value="1" selected="selected">Yes</option>
268
                                  <option value="0" selected="selected">No</option>
271
                                  [% ELSE %]
269
                                  <option value="1">Yes</option>
272
                                    <option value="0" selected="selected">No</option>
270
                                [% END %]
273
                                    <option value="1">Yes</option>
271
                              </select>
274
                                  [% END %]
275
                                </select>
276
                              [% ELSE %]
277
                                <input type="hidden" name="mapping_facet" value="0" />
278
                                No
279
                              [% END %]
272
                            </td>
280
                            </td>
273
                            <td>
281
                            <td>
274
                              <select name="mapping_suggestible">
282
                              <select name="mapping_suggestible">
Lines 332-337 a.add, a.delete { Link Here
332
                        </tr>
340
                        </tr>
333
                      </tfoot>
341
                      </tfoot>
334
                    </table>
342
                    </table>
343
344
                    [% IF index.index_name == 'biblios' %]
345
                        <h3>Facet order</h3>
346
                        <div id="facet_[% index.index_name %]">
347
                            <table>
348
                                <thead>
349
                                    <tr>
350
                                        <th>Search field</th>
351
                                        <th>Label</th>
352
                                        <th>Display</th>
353
                                    </tr>
354
                                </thead>
355
                                <tbody>
356
                                    [% FOREACH f IN facetable_fields %]
357
                                        <tr>
358
                                            <td>
359
                                                [% f.name %]
360
                                            </td>
361
                                            <td>
362
                                                [% SWITCH f.name %]
363
                                                [% CASE 'author' %]Authors
364
                                                [% CASE 'itype' %]Item Types
365
                                                [% CASE 'location' %]Locations
366
                                                [% CASE 'su-geo' %]Places
367
                                                [% CASE 'se' %]Series
368
                                                [% CASE 'subject' %]Topics
369
                                                [% CASE 'ccode' %]Collections
370
                                                [% CASE 'holdingbranch' %]Holding libraries
371
                                                [% CASE 'homebranch' %]Home libraries
372
                                                [% CASE %][% f %]
373
                                                [% END %]
374
                                            </td>
375
                                            <td>
376
                                                [% IF f.facet_order %]
377
                                                    <input type="checkbox" name="display_facet" value="[% f.name %]" checked="checked" />
378
                                                [% ELSE %]
379
                                                    <input type="checkbox" name="display_facet" value="[% f.name %]" />
380
                                                [% END %]
381
                                            </td>
382
                                        </tr>
383
                                    [% END %]
384
                                </tbody>
385
                            </table>
386
                        </div>
387
                    [% END %]
335
                </div>
388
                </div>
336
            [% END %]
389
            [% END %]
337
        </div>
390
        </div>
338
- 

Return to bug 18235