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

(-)a/Koha/SearchEngine/Elasticsearch.pm (-1 / +25 lines)
Lines 287-293 sub reset_elasticsearch_mappings { Link Here
287
            my $field_type = $data->{type};
287
            my $field_type = $data->{type};
288
            my $field_label = $data->{label};
288
            my $field_label = $data->{label};
289
            my $mappings = $data->{mappings};
289
            my $mappings = $data->{mappings};
290
            my $search_field = Koha::SearchFields->find_or_create({ name => $field_name, label => $field_label, type => $field_type }, { key => 'name' });
290
            my $facet_order = $data->{facet_order};
291
            my $search_field = Koha::SearchFields->find_or_create({ name => $field_name });
292
            $search_field->update(
293
                {
294
                    label       => $field_label,
295
                    type        => $field_type,
296
                    facet_order => $facet_order
297
                }
298
            );
291
            for my $mapping ( @$mappings ) {
299
            for my $mapping ( @$mappings ) {
292
                my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} });
300
                my $marc_field = Koha::SearchMarcMaps->find_or_create({ index_name => $index_name, marc_type => $mapping->{marc_type}, marc_field => $mapping->{marc_field} });
293
                $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet} || 0, suggestible => $mapping->{suggestible} || 0, sort => $mapping->{sort} } );
301
                $search_field->add_to_search_marc_maps($marc_field, { facet => $mapping->{facet} || 0, suggestible => $mapping->{suggestible} || 0, sort => $mapping->{sort} } );
Lines 537-542 sub _read_configuration { Link Here
537
    return $configuration;
545
    return $configuration;
538
}
546
}
539
547
548
sub get_facetable_fields {
549
    my ($self) = @_;
550
551
    # These should correspond to the ES field names, as opposed to the CCL
552
    # things that zebra uses.
553
    my @search_field_names = qw( author itype location su-geo se subject ccode holdingbranch homebranch );
554
    my @faceted_fields = Koha::SearchFields->search(
555
        { name => { -in => \@search_field_names }, facet_order => { '!=' => undef } }, { order_by => ['facet_order'] }
556
    );
557
    my @not_faceted_fields = Koha::SearchFields->search(
558
        { name => { -in => \@search_field_names }, facet_order => undef }, { order_by => ['facet_order'] }
559
    );
560
    # This could certainly be improved
561
    return ( @faceted_fields, @not_faceted_fields );
562
}
563
540
1;
564
1;
541
565
542
__END__
566
__END__
(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (-12 / +18 lines)
Lines 423-440 sub _convert_facets { Link Here
423
423
424
    # These should correspond to the ES field names, as opposed to the CCL
424
    # These should correspond to the ES field names, as opposed to the CCL
425
    # things that zebra uses.
425
    # things that zebra uses.
426
    # TODO let the library define the order using the interface.
426
    my %type_to_label;
427
    my %type_to_label = (
427
    my %label = (
428
        author   => { order => 1, label => 'Authors', },
428
        author        => 'Authors',
429
        itype    => { order => 2, label => 'ItemTypes', },
429
        itype         => 'ItemTypes',
430
        location => { order => 3, label => 'Location', },
430
        location      => 'Location',
431
        'su-geo' => { order => 4, label => 'Places', },
431
        'su-geo'      => 'Places',
432
        se       => { order => 5, label => 'Series', },
432
        se            => 'Series',
433
        subject  => { order => 6, label => 'Topics', },
433
        subject       => 'Topics',
434
        ccode    => { order => 7, label => 'CollectionCodes',},
434
        ccode         => 'CollectionCodes',
435
        holdingbranch => { order => 8, label => 'HoldingLibrary' },
435
        holdingbranch => 'HoldingLibrary',
436
        homebranch => { order => 9, label => 'HomeLibrary' }
436
        homebranch    => 'HomeLibrary',
437
    );
437
    );
438
    my @facetable_fields =
439
      Koha::SearchEngine::Elasticsearch->get_facetable_fields;
440
    for my $f (@facetable_fields) {
441
        next unless defined $f->facet_order;
442
        $type_to_label{ $f->name } =
443
          { order => $f->facet_order, label => $label{ $f->name } };
444
    }
438
445
439
    # We also have some special cases, e.g. itypes that need to show the
446
    # We also have some special cases, e.g. itypes that need to show the
440
    # value rather than the code.
447
    # value rather than the code.
Lines 492-496 sub _convert_facets { Link Here
492
    return \@facets;
499
    return \@facets;
493
}
500
}
494
501
495
496
1;
502
1;
(-)a/admin/searchengine/elasticsearch/mappings.pl (-10 / +24 lines)
Lines 17-22 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use CGI;
19
use CGI;
20
use List::Util qw( first );
20
use C4::Koha;
21
use C4::Koha;
21
use C4::Output;
22
use C4::Output;
22
use C4::Auth;
23
use C4::Auth;
Lines 48-63 if ( $op eq 'edit' ) { Link Here
48
49
49
    $schema->storage->txn_begin;
50
    $schema->storage->txn_begin;
50
51
51
    my @field_name = $input->param('search_field_name');
52
    my @field_name = $input->multi_param('search_field_name');
52
    my @field_label = $input->param('search_field_label');
53
    my @field_label = $input->multi_param('search_field_label');
53
    my @field_type = $input->param('search_field_type');
54
    my @field_type = $input->multi_param('search_field_type');
54
55
55
    my @index_name          = $input->param('mapping_index_name');
56
    my @index_name          = $input->multi_param('mapping_index_name');
56
    my @search_field_name  = $input->param('mapping_search_field_name');
57
    my @search_field_name  = $input->multi_param('mapping_search_field_name');
57
    my @mapping_sort        = $input->param('mapping_sort');
58
    my @mapping_sort        = $input->multi_param('mapping_sort');
58
    my @mapping_facet       = $input->param('mapping_facet');
59
    my @mapping_facet       = $input->multi_param('mapping_facet');
59
    my @mapping_suggestible = $input->param('mapping_suggestible');
60
    my @mapping_suggestible = $input->multi_param('mapping_suggestible');
60
    my @mapping_marc_field  = $input->param('mapping_marc_field');
61
    my @mapping_marc_field  = $input->multi_param('mapping_marc_field');
62
    my @faceted_field_names = $input->multi_param('display_facet');
61
63
62
    eval {
64
    eval {
63
65
Lines 68-77 if ( $op eq 'edit' ) { Link Here
68
            my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } );
70
            my $search_field = Koha::SearchFields->find( { name => $field_name }, { key => 'name' } );
69
            $search_field->label($field_label);
71
            $search_field->label($field_label);
70
            $search_field->type($field_type);
72
            $search_field->type($field_type);
73
            my $facet_order = first { $faceted_field_names[$_] eq $field_name } 0 .. $#faceted_field_names;
74
            $search_field->facet_order(defined $facet_order ? $facet_order + 1 : undef);
71
            $search_field->store;
75
            $search_field->store;
72
        }
76
        }
73
77
74
        Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete;
78
        Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete;
79
        my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields();
80
        my @facetable_field_names = map { $_->name } @facetable_fields;
75
81
76
        for my $i ( 0 .. scalar(@index_name) - 1 ) {
82
        for my $i ( 0 .. scalar(@index_name) - 1 ) {
77
            my $index_name          = $index_name[$i];
83
            my $index_name          = $index_name[$i];
Lines 81-86 if ( $op eq 'edit' ) { Link Here
81
            my $mapping_suggestible = $mapping_suggestible[$i];
87
            my $mapping_suggestible = $mapping_suggestible[$i];
82
            my $mapping_sort        = $mapping_sort[$i];
88
            my $mapping_sort        = $mapping_sort[$i];
83
            $mapping_sort = undef if $mapping_sort eq 'undef';
89
            $mapping_sort = undef if $mapping_sort eq 'undef';
90
            $mapping_facet = ( grep {/^$search_field_name$/} @facetable_field_names ) ? $mapping_facet : 0;
84
91
85
            my $search_field = Koha::SearchFields->find({ name => $search_field_name }, { key => 'name' });
92
            my $search_field = Koha::SearchFields->find({ name => $search_field_name }, { key => 'name' });
86
            # TODO Check mapping format
93
            # TODO Check mapping format
Lines 118-132 for my $index_name (qw| biblios authorities |) { Link Here
118
    );
125
    );
119
126
120
    my @mappings;
127
    my @mappings;
128
    my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields();
129
    my @facetable_field_names = map { $_->name } @facetable_fields;
130
121
    while ( my $s = $search_fields->next ) {
131
    while ( my $s = $search_fields->next ) {
132
        my $name = $s->name;
122
        push @mappings,
133
        push @mappings,
123
          { search_field_name  => $s->name,
134
          { search_field_name  => $name,
124
            search_field_label => $s->label,
135
            search_field_label => $s->label,
125
            search_field_type  => $s->type,
136
            search_field_type  => $s->type,
126
            marc_field         => $s->get_column('marc_field'),
137
            marc_field         => $s->get_column('marc_field'),
127
            sort               => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc"
138
            sort               => $s->get_column('sort') // 'undef', # To avoid warnings "Use of uninitialized value in lc"
128
            suggestible        => $s->get_column('suggestible'),
139
            suggestible        => $s->get_column('suggestible'),
129
            facet              => $s->get_column('facet'),
140
            facet              => $s->get_column('facet'),
141
            is_facetable       => ( grep {/^$name$/} @facetable_field_names ) ? 1 : 0,
130
          };
142
          };
131
    }
143
    }
132
144
Lines 135-143 for my $index_name (qw| biblios authorities |) { Link Here
135
147
136
my $search_fields = $schema->resultset('SearchField')->search;
148
my $search_fields = $schema->resultset('SearchField')->search;
137
my @all_search_fields = $search_fields->search( {}, { order_by => ['name'] } );
149
my @all_search_fields = $search_fields->search( {}, { order_by => ['name'] } );
150
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields();
138
$template->param(
151
$template->param(
139
    indexes           => \@indexes,
152
    indexes           => \@indexes,
140
    all_search_fields => \@all_search_fields,
153
    all_search_fields => \@all_search_fields,
154
    facetable_fields  => \@facetable_fields,
141
    messages          => \@messages,
155
    messages          => \@messages,
142
);
156
);
143
157
(-)a/admin/searchengine/elasticsearch/mappings.yaml (+9 lines)
Lines 1194-1199 biblios: Link Here
1194
        sort: 0
1194
        sort: 0
1195
        suggestible: 0
1195
        suggestible: 0
1196
    type: string
1196
    type: string
1197
    facet_order: 1
1197
  bgf-number:
1198
  bgf-number:
1198
    label: bgf-number
1199
    label: bgf-number
1199
    mappings:
1200
    mappings:
Lines 1274-1279 biblios: Link Here
1274
       sort: ~
1275
       sort: ~
1275
       suggestible: ''
1276
       suggestible: ''
1276
    type: ''
1277
    type: ''
1278
    facet_order: 7
1277
  control-number:
1279
  control-number:
1278
    label: control-number
1280
    label: control-number
1279
    mappings:
1281
    mappings:
Lines 1462-1467 biblios: Link Here
1462
        sort: ~
1464
        sort: ~
1463
        suggestible: ''
1465
        suggestible: ''
1464
    type: string
1466
    type: string
1467
    facet_order: 8
1465
  homebranch:
1468
  homebranch:
1466
    label: HomeLibrary
1469
    label: HomeLibrary
1467
    mappings:
1470
    mappings:
Lines 1481-1486 biblios: Link Here
1481
        sort: ~
1484
        sort: ~
1482
        suggestible: ''
1485
        suggestible: ''
1483
    type: string
1486
    type: string
1487
    facet_order: 9
1484
  identifier-standard:
1488
  identifier-standard:
1485
    label: identifier-standard
1489
    label: identifier-standard
1486
    mappings:
1490
    mappings:
Lines 1655-1660 biblios: Link Here
1655
        sort: ~
1659
        sort: ~
1656
        suggestible: ''
1660
        suggestible: ''
1657
    type: string
1661
    type: string
1662
    facet_order: 2
1658
  lc-cardnumber:
1663
  lc-cardnumber:
1659
    label: lc-cardnumber
1664
    label: lc-cardnumber
1660
    mappings:
1665
    mappings:
Lines 1774-1779 biblios: Link Here
1774
        sort: ~
1779
        sort: ~
1775
        suggestible: ''
1780
        suggestible: ''
1776
    type: ''
1781
    type: ''
1782
    facet_order: 3
1777
  material-type:
1783
  material-type:
1778
    label: material-type
1784
    label: material-type
1779
    mappings:
1785
    mappings:
Lines 2005-2010 biblios: Link Here
2005
        sort: ~
2011
        sort: ~
2006
        suggestible: ''
2012
        suggestible: ''
2007
    type: string
2013
    type: string
2014
    facet_order: 5
2008
  su-geo:
2015
  su-geo:
2009
    label: su-geo
2016
    label: su-geo
2010
    mappings:
2017
    mappings:
Lines 2024-2029 biblios: Link Here
2024
        sort: ~
2031
        sort: ~
2025
        suggestible: ''
2032
        suggestible: ''
2026
    type: string
2033
    type: string
2034
    facet_order: 4
2027
  subject:
2035
  subject:
2028
    label: subject
2036
    label: subject
2029
    mappings:
2037
    mappings:
Lines 2248-2253 biblios: Link Here
2248
        sort: ~
2256
        sort: ~
2249
        suggestible: '1'
2257
        suggestible: '1'
2250
    type: string
2258
    type: string
2259
    facet_order: 6
2251
  suppress:
2260
  suppress:
2252
    label: suppress
2261
    label: suppress
2253
    mappings:
2262
    mappings:
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-10 / +62 lines)
Lines 50-55 Link Here
50
                } );
50
                } );
51
            }
51
            }
52
        });
52
        });
53
        $("#facet_biblios > table").tableDnD( {
54
            onDragClass: "dragClass",
55
        } );
53
    });
56
    });
54
</script>
57
</script>
55
<style type="text/css">
58
<style type="text/css">
Lines 211-225 a.add, a.delete { Link Here
211
                              </select>
214
                              </select>
212
                            </td>
215
                            </td>
213
                            <td>
216
                            <td>
214
                              <select name="mapping_facet">
217
                              [% IF mapping.is_facetable %]
215
                                [% IF mapping.facet %]
218
                                <select name="mapping_facet">
216
                                  <option value="0">No</option>
219
                                  [% IF mapping.facet %]
217
                                  <option value="1" selected="selected">Yes</option>
220
                                    <option value="0">No</option>
218
                                [% ELSE %]
221
                                    <option value="1" selected="selected">Yes</option>
219
                                  <option value="0" selected="selected">No</option>
222
                                  [% ELSE %]
220
                                  <option value="1">Yes</option>
223
                                    <option value="0" selected="selected">No</option>
221
                                [% END %]
224
                                    <option value="1">Yes</option>
222
                              </select>
225
                                  [% END %]
226
                                </select>
227
                              [% ELSE %]
228
                                <input type="hidden" name="mapping_facet" value="0" />
229
                                No
230
                              [% END %]
223
                            </td>
231
                            </td>
224
                            <td>
232
                            <td>
225
                              <select name="mapping_suggestible">
233
                              <select name="mapping_suggestible">
Lines 283-288 a.add, a.delete { Link Here
283
                        </tr>
291
                        </tr>
284
                      </tfoot>
292
                      </tfoot>
285
                    </table>
293
                    </table>
294
295
                    [% IF index.index_name == 'biblios' %]
296
                        <h3>Facet order</h3>
297
                        <div id="facet_[% index.index_name %]">
298
                            <table>
299
                                <thead>
300
                                    <tr>
301
                                        <th>Search field</th>
302
                                        <th>Label</th>
303
                                        <th>Display</th>
304
                                    </tr>
305
                                </thead>
306
                                <tbody>
307
                                    [% FOREACH f IN facetable_fields %]
308
                                        <tr>
309
                                            <td>
310
                                                [% f.name %]
311
                                            </td>
312
                                            <td>
313
                                                [% SWITCH f.name %]
314
                                                [% CASE 'author' %]Authors
315
                                                [% CASE 'itype' %]Item Types
316
                                                [% CASE 'location' %]Locations
317
                                                [% CASE 'su-geo' %]Places
318
                                                [% CASE 'se' %]Series
319
                                                [% CASE 'subject' %]Topics
320
                                                [% CASE 'ccode' %]Collections
321
                                                [% CASE 'holdingbranch' %]Holding libraries
322
                                                [% CASE 'homebranch' %]Home libraries
323
                                                [% CASE %][% f %]
324
                                                [% END %]
325
                                            </td>
326
                                            <td>
327
                                                [% IF f.facet_order %]
328
                                                    <input type="checkbox" name="display_facet" value="[% f.name %]" checked="checked" />
329
                                                [% ELSE %]
330
                                                    <input type="checkbox" name="display_facet" value="[% f.name %]" />
331
                                                [% END %]
332
                                            </td>
333
                                        </tr>
334
                                    [% END %]
335
                                </tbody>
336
                            </table>
337
                        </div>
338
                    [% END %]
286
                </div>
339
                </div>
287
            [% END %]
340
            [% END %]
288
        </div>
341
        </div>
289
- 

Return to bug 18235