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 954-959 sub _read_configuration { Link Here
954
    return $configuration;
962
    return $configuration;
955
}
963
}
956
964
965
sub get_facetable_fields {
966
    my ($self) = @_;
967
968
    # These should correspond to the ES field names, as opposed to the CCL
969
    # things that zebra uses.
970
    my @search_field_names = qw( author itype location su-geo se subject ccode holdingbranch homebranch );
971
    my @faceted_fields = Koha::SearchFields->search(
972
        { name => { -in => \@search_field_names }, facet_order => { '!=' => undef } }, { order_by => ['facet_order'] }
973
    );
974
    my @not_faceted_fields = Koha::SearchFields->search(
975
        { name => { -in => \@search_field_names }, facet_order => undef }, { order_by => ['facet_order'] }
976
    );
977
    # This could certainly be improved
978
    return ( @faceted_fields, @not_faceted_fields );
979
}
980
957
1;
981
1;
958
982
959
__END__
983
__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
        se       => { order => 5, label => 'Series', },
445
        se            => '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 (+9 lines)
Lines 1808-1813 biblios: Link Here
1808
        sort: 0
1808
        sort: 0
1809
        suggestible: 0
1809
        suggestible: 0
1810
    type: string
1810
    type: string
1811
    facet_order: 1
1811
  bgf-number:
1812
  bgf-number:
1812
    label: bgf-number
1813
    label: bgf-number
1813
    mappings:
1814
    mappings:
Lines 1888-1893 biblios: Link Here
1888
       sort: ~
1889
       sort: ~
1889
       suggestible: ''
1890
       suggestible: ''
1890
    type: ''
1891
    type: ''
1892
    facet_order: 7
1891
  control-number:
1893
  control-number:
1892
    label: control-number
1894
    label: control-number
1893
    mappings:
1895
    mappings:
Lines 2076-2081 biblios: Link Here
2076
        sort: ~
2078
        sort: ~
2077
        suggestible: ''
2079
        suggestible: ''
2078
    type: string
2080
    type: string
2081
    facet_order: 8
2079
  homebranch:
2082
  homebranch:
2080
    label: HomeLibrary
2083
    label: HomeLibrary
2081
    mappings:
2084
    mappings:
Lines 2095-2100 biblios: Link Here
2095
        sort: ~
2098
        sort: ~
2096
        suggestible: ''
2099
        suggestible: ''
2097
    type: string
2100
    type: string
2101
    facet_order: 9
2098
  identifier-standard:
2102
  identifier-standard:
2099
    label: identifier-standard
2103
    label: identifier-standard
2100
    mappings:
2104
    mappings:
Lines 2269-2274 biblios: Link Here
2269
        sort: ~
2273
        sort: ~
2270
        suggestible: ''
2274
        suggestible: ''
2271
    type: string
2275
    type: string
2276
    facet_order: 2
2272
  lc-cardnumber:
2277
  lc-cardnumber:
2273
    label: lc-cardnumber
2278
    label: lc-cardnumber
2274
    mappings:
2279
    mappings:
Lines 2388-2393 biblios: Link Here
2388
        sort: ~
2393
        sort: ~
2389
        suggestible: ''
2394
        suggestible: ''
2390
    type: ''
2395
    type: ''
2396
    facet_order: 3
2391
  material-type:
2397
  material-type:
2392
    label: material-type
2398
    label: material-type
2393
    mappings:
2399
    mappings:
Lines 2619-2624 biblios: Link Here
2619
        sort: ~
2625
        sort: ~
2620
        suggestible: ''
2626
        suggestible: ''
2621
    type: string
2627
    type: string
2628
    facet_order: 5
2622
  su-geo:
2629
  su-geo:
2623
    label: su-geo
2630
    label: su-geo
2624
    mappings:
2631
    mappings:
Lines 2638-2643 biblios: Link Here
2638
        sort: ~
2645
        sort: ~
2639
        suggestible: ''
2646
        suggestible: ''
2640
    type: string
2647
    type: string
2648
    facet_order: 4
2641
  subject:
2649
  subject:
2642
    label: subject
2650
    label: subject
2643
    mappings:
2651
    mappings:
Lines 2862-2867 biblios: Link Here
2862
        sort: ~
2870
        sort: ~
2863
        suggestible: '1'
2871
        suggestible: '1'
2864
    type: string
2872
    type: string
2873
    facet_order: 6
2865
  suppress:
2874
  suppress:
2866
    label: suppress
2875
    label: suppress
2867
    mappings:
2876
    mappings:
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-10 / +62 lines)
Lines 52-57 Link Here
52
                } );
52
                } );
53
            }
53
            }
54
        });
54
        });
55
        $("#facet_biblios > table").tableDnD( {
56
            onDragClass: "dragClass",
57
        } );
55
    });
58
    });
56
</script>
59
</script>
57
<style>
60
<style>
Lines 259-273 a.add, a.delete { Link Here
259
                              </select>
262
                              </select>
260
                            </td>
263
                            </td>
261
                            <td>
264
                            <td>
262
                              <select name="mapping_facet">
265
                              [% IF mapping.is_facetable %]
263
                                [% IF mapping.facet %]
266
                                <select name="mapping_facet">
264
                                  <option value="0">No</option>
267
                                  [% IF mapping.facet %]
265
                                  <option value="1" selected="selected">Yes</option>
268
                                    <option value="0">No</option>
266
                                [% ELSE %]
269
                                    <option value="1" selected="selected">Yes</option>
267
                                  <option value="0" selected="selected">No</option>
270
                                  [% ELSE %]
268
                                  <option value="1">Yes</option>
271
                                    <option value="0" selected="selected">No</option>
269
                                [% END %]
272
                                    <option value="1">Yes</option>
270
                              </select>
273
                                  [% END %]
274
                                </select>
275
                              [% ELSE %]
276
                                <input type="hidden" name="mapping_facet" value="0" />
277
                                No
278
                              [% END %]
271
                            </td>
279
                            </td>
272
                            <td>
280
                            <td>
273
                              <select name="mapping_suggestible">
281
                              <select name="mapping_suggestible">
Lines 331-336 a.add, a.delete { Link Here
331
                        </tr>
339
                        </tr>
332
                      </tfoot>
340
                      </tfoot>
333
                    </table>
341
                    </table>
342
343
                    [% IF index.index_name == 'biblios' %]
344
                        <h3>Facet order</h3>
345
                        <div id="facet_[% index.index_name %]">
346
                            <table>
347
                                <thead>
348
                                    <tr>
349
                                        <th>Search field</th>
350
                                        <th>Label</th>
351
                                        <th>Display</th>
352
                                    </tr>
353
                                </thead>
354
                                <tbody>
355
                                    [% FOREACH f IN facetable_fields %]
356
                                        <tr>
357
                                            <td>
358
                                                [% f.name %]
359
                                            </td>
360
                                            <td>
361
                                                [% SWITCH f.name %]
362
                                                [% CASE 'author' %]Authors
363
                                                [% CASE 'itype' %]Item Types
364
                                                [% CASE 'location' %]Locations
365
                                                [% CASE 'su-geo' %]Places
366
                                                [% CASE 'se' %]Series
367
                                                [% CASE 'subject' %]Topics
368
                                                [% CASE 'ccode' %]Collections
369
                                                [% CASE 'holdingbranch' %]Holding libraries
370
                                                [% CASE 'homebranch' %]Home libraries
371
                                                [% CASE %][% f %]
372
                                                [% END %]
373
                                            </td>
374
                                            <td>
375
                                                [% IF f.facet_order %]
376
                                                    <input type="checkbox" name="display_facet" value="[% f.name %]" checked="checked" />
377
                                                [% ELSE %]
378
                                                    <input type="checkbox" name="display_facet" value="[% f.name %]" />
379
                                                [% END %]
380
                                            </td>
381
                                        </tr>
382
                                    [% END %]
383
                                </tbody>
384
                            </table>
385
                        </div>
386
                    [% END %]
334
                </div>
387
                </div>
335
            [% END %]
388
            [% END %]
336
        </div>
389
        </div>
337
- 

Return to bug 18235