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

(-)a/C4/Search.pm (+1 lines)
Lines 579-584 sub getRecords { Link Here
579
                            "type_label_"
579
                            "type_label_"
580
                              . $facets_info->{$link_value}->{'label_value'} =>
580
                              . $facets_info->{$link_value}->{'label_value'} =>
581
                              1,
581
                              1,
582
                            label      => $facets_info->{$link_value}->{'label_value'},
582
                            facets     => \@this_facets_array,
583
                            facets     => \@this_facets_array,
583
                          }
584
                          }
584
                          unless (
585
                          unless (
(-)a/Koha/SearchEngine/Elasticsearch.pm (-15 / +6 lines)
Lines 28-33 use Koha::Filter::MARC::EmbedSeeFromHeadings; Link Here
28
use Koha::SearchFields;
28
use Koha::SearchFields;
29
use Koha::SearchMarcMaps;
29
use Koha::SearchMarcMaps;
30
use Koha::Caches;
30
use Koha::Caches;
31
use Koha::AuthorisedValueCategories;
31
use C4::Heading;
32
use C4::Heading;
32
use C4::AuthoritiesMarc qw( GuessAuthTypeCode );
33
use C4::AuthoritiesMarc qw( GuessAuthTypeCode );
33
use C4::Biblio;
34
use C4::Biblio;
Lines 1391-1418 sub _read_configuration { Link Here
1391
    return $configuration;
1392
    return $configuration;
1392
}
1393
}
1393
1394
1394
=head2 get_facetable_fields
1395
=head2 get_facet_fields
1395
1396
1396
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields();
1397
my @facet_fields = Koha::SearchEngine::Elasticsearch->get_facet_fields();
1397
1398
1398
Returns the list of Koha::SearchFields marked to be faceted in the ES configuration
1399
Returns the list of Koha::SearchFields marked to be faceted.
1399
1400
1400
=cut
1401
=cut
1401
1402
1402
sub get_facetable_fields {
1403
sub get_facet_fields {
1403
    my ($self) = @_;
1404
    my ($self) = @_;
1404
1405
1405
    # These should correspond to the ES field names, as opposed to the CCL
1406
    return Koha::SearchFields->search( { facet_order => { '!=' => undef } }, { order_by => ['facet_order'] } )->as_list;
1406
    # things that zebra uses.
1407
    my @search_field_names = qw( author itype location su-geo title-series subject ccode holdingbranch homebranch ln );
1408
    my @faceted_fields = Koha::SearchFields->search(
1409
        { name => { -in => \@search_field_names }, facet_order => { '!=' => undef } }, { order_by => ['facet_order'] }
1410
    )->as_list;
1411
    my @not_faceted_fields = Koha::SearchFields->search(
1412
        { name => { -in => \@search_field_names }, facet_order => undef }, { order_by => ['facet_order'] }
1413
    )->as_list;
1414
    # This could certainly be improved
1415
    return ( @faceted_fields, @not_faceted_fields );
1416
}
1407
}
1417
1408
1418
=head2 clear_search_fields_cache
1409
=head2 clear_search_fields_cache
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-18 / +15 lines)
Lines 48-53 use URI::Escape qw( uri_escape_utf8 ); Link Here
48
use C4::Context;
48
use C4::Context;
49
use Koha::Exceptions;
49
use Koha::Exceptions;
50
use Koha::Caches;
50
use Koha::Caches;
51
use Koha::AuthorisedValueCategories;
51
52
52
our %index_field_convert = (
53
our %index_field_convert = (
53
    'kw' => '',
54
    'kw' => '',
Lines 225-250 sub build_query { Link Here
225
    # See _convert_facets in Search.pm for how these get turned into
226
    # See _convert_facets in Search.pm for how these get turned into
226
    # things that Koha can use.
227
    # things that Koha can use.
227
    my $size = C4::Context->preference('FacetMaxCount');
228
    my $size = C4::Context->preference('FacetMaxCount');
228
    $res->{aggregations} = {
229
    my @facets = Koha::SearchEngine::Elasticsearch->get_facet_fields;
229
        author         => { terms => { field => "author__facet" , size => $size } },
230
    for my $f ( @facets ) {
230
        subject        => { terms => { field => "subject__facet", size => $size } },
231
        my $name = $f->name;
231
        itype          => { terms => { field => "itype__facet", size => $size} },
232
        $res->{aggregations}->{$name} = { terms => { field => "${name}__facet" , size => $size } };
232
        location       => { terms => { field => "location__facet", size => $size } },
233
        'su-geo'       => { terms => { field => "su-geo__facet", size => $size} },
234
        'title-series' => { terms => { field => "title-series__facet", size => $size } },
235
        ccode          => { terms => { field => "ccode__facet", size => $size } },
236
        ln             => { terms => { field => "ln__facet", size => $size } },
237
    };
233
    };
238
234
239
    my $display_library_facets = C4::Context->preference('DisplayLibraryFacets');
235
    # FIXME We need a way to show/hide the facet individually
240
    if (   $display_library_facets eq 'both'
236
    #my $display_library_facets = C4::Context->preference('DisplayLibraryFacets');
241
        or $display_library_facets eq 'home' ) {
237
    #if (   $display_library_facets eq 'both'
242
        $res->{aggregations}{homebranch} = { terms => { field => "homebranch__facet", size => $size } };
238
    #    or $display_library_facets eq 'home' ) {
243
    }
239
    #    $res->{aggregations}{homebranch} = { terms => { field => "homebranch__facet", size => $size } };
244
    if (   $display_library_facets eq 'both'
240
    #}
245
        or $display_library_facets eq 'holding' ) {
241
    #if (   $display_library_facets eq 'both'
246
        $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet", size => $size } };
242
    #    or $display_library_facets eq 'holding' ) {
247
    }
243
    #    $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet", size => $size } };
244
    #}
248
    return $res;
245
    return $res;
249
}
246
}
250
247
(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (-22 / +4 lines)
Lines 45-50 use C4::Context; Link Here
45
use C4::AuthoritiesMarc;
45
use C4::AuthoritiesMarc;
46
use Koha::ItemTypes;
46
use Koha::ItemTypes;
47
use Koha::AuthorisedValues;
47
use Koha::AuthorisedValues;
48
use Koha::AuthorisedValueCategories;
48
use Koha::SearchEngine::QueryBuilder;
49
use Koha::SearchEngine::QueryBuilder;
49
use Koha::SearchEngine::Search;
50
use Koha::SearchEngine::Search;
50
use Koha::Exceptions::Elasticsearch;
51
use Koha::Exceptions::Elasticsearch;
Lines 440-467 sub _convert_facets { Link Here
440
441
441
    return if !$es;
442
    return if !$es;
442
443
443
    # These should correspond to the ES field names, as opposed to the CCL
444
    my %type_to_label = map { $_->name => { order => $_->facet_order, label => $_->label } }
444
    # things that zebra uses.
445
        Koha::SearchEngine::Elasticsearch->get_facet_fields;
445
    my %type_to_label;
446
    my %label = (
447
        author         => 'Authors',
448
        itype          => 'ItemTypes',
449
        location       => 'Location',
450
        'su-geo'       => 'Places',
451
        'title-series' => 'Series',
452
        subject        => 'Topics',
453
        ccode          => 'CollectionCodes',
454
        holdingbranch  => 'HoldingLibrary',
455
        homebranch     => 'HomeLibrary',
456
        ln             => 'Language',
457
    );
458
    my @facetable_fields =
459
      Koha::SearchEngine::Elasticsearch->get_facetable_fields;
460
    for my $f (@facetable_fields) {
461
        next unless defined $f->facet_order;
462
        $type_to_label{ $f->name } =
463
          { order => $f->facet_order, label => $label{ $f->name } };
464
    }
465
446
466
    # We also have some special cases, e.g. itypes that need to show the
447
    # We also have some special cases, e.g. itypes that need to show the
467
    # value rather than the code.
448
    # value rather than the code.
Lines 486-491 sub _convert_facets { Link Here
486
        my $facet = {
467
        my $facet = {
487
            type_id    => $type . '_id',
468
            type_id    => $type . '_id',
488
            "type_label_$type_to_label{$type}{label}" => 1,
469
            "type_label_$type_to_label{$type}{label}" => 1,
470
            label => $type_to_label{$type}{label},
489
            type_link_value                    => $type,
471
            type_link_value                    => $type,
490
            order      => $type_to_label{$type}{order},
472
            order      => $type_to_label{$type}{order},
491
        };
473
        };
(-)a/admin/searchengine/elasticsearch/mappings.pl (-3 / +3 lines)
Lines 105-111 if ( $op eq 'cud-edit' ) { Link Here
105
    my @mapping_search      = $input->multi_param('mapping_search');
105
    my @mapping_search      = $input->multi_param('mapping_search');
106
    my @mapping_filter      = $input->multi_param('mapping_filter');
106
    my @mapping_filter      = $input->multi_param('mapping_filter');
107
    my @mapping_marc_field  = $input->multi_param('mapping_marc_field');
107
    my @mapping_marc_field  = $input->multi_param('mapping_marc_field');
108
    my @faceted_field_names = $input->multi_param('display_facet');
108
    my @faceted_field_names = $input->multi_param('facet_name');
109
109
110
    eval {
110
    eval {
111
111
Lines 143-149 if ( $op eq 'cud-edit' ) { Link Here
143
        }
143
        }
144
144
145
        Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete;
145
        Koha::SearchMarcMaps->search( { marc_type => $marc_type, } )->delete;
146
        my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields();
146
        my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facet_fields();
147
        my @facetable_field_names = map { $_->name } @facetable_fields;
147
        my @facetable_field_names = map { $_->name } @facetable_fields;
148
148
149
        my $mandatory_before = Koha::SearchFields->search({mandatory=>1})->count;
149
        my $mandatory_before = Koha::SearchFields->search({mandatory=>1})->count;
Lines 232-238 for my $index_name (@index_names) { Link Here
232
    }
232
    }
233
}
233
}
234
234
235
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facetable_fields();
235
my @facetable_fields = Koha::SearchEngine::Elasticsearch->get_facet_fields();
236
for my $index_name (@index_names) {
236
for my $index_name (@index_names) {
237
    my $search_fields = Koha::SearchFields->search(
237
    my $search_fields = Koha::SearchFields->search(
238
        {
238
        {
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc (-21 / +14 lines)
Lines 51-88 Link Here
51
                    [% IF facets_loo.facets.size > 0 %]
51
                    [% IF facets_loo.facets.size > 0 %]
52
                        <li id="[% facets_loo.type_id | html %]">
52
                        <li id="[% facets_loo.type_id | html %]">
53
                            [% facets_loo.type_label | html %]
53
                            [% facets_loo.type_label | html %]
54
                            [% IF facets_loo.type_label_Authors %]
54
                            [% SWITCH facets_loo.label %]
55
                            [% CASE 'Authors' %]
55
                                <span id="facet-authors">Authors</span>
56
                                <span id="facet-authors">Authors</span>
56
                            [% END %]
57
                            [% CASE 'Titles' %]
57
                            [% IF facets_loo.type_label_Titles %]
58
                                <span id="facet-titles">Titles</span>
58
                                <span id="facet-titles">Titles</span>
59
                            [% END %]
59
                            [% CASE 'Topics' %]
60
                            [% IF facets_loo.type_label_Topics %]
61
                                <span id="facet-topics">Topics</span>
60
                                <span id="facet-topics">Topics</span>
62
                            [% END %]
61
                            [% CASE 'Places' %]
63
                            [% IF facets_loo.type_label_Places %]
64
                                <span id="facet-places">Places</span>
62
                                <span id="facet-places">Places</span>
65
                            [% END %]
63
                            [% CASE 'Series' %]
66
                            [% IF facets_loo.type_label_Series %]
67
                                <span id="facet-series">Series</span>
64
                                <span id="facet-series">Series</span>
68
                            [% END %]
65
                            [% CASE 'ItemTypes' %]
69
                            [% IF facets_loo.type_label_ItemTypes %]
70
                                <span id="facet-itemtypes">Item types</span>
66
                                <span id="facet-itemtypes">Item types</span>
71
                            [% END %]
67
                            [% CASE 'HomeLibrary' %]
72
                            [% IF ( facets_loo.type_label_HomeLibrary ) %]
73
                                <span id="facet-home-libraries">Home libraries</span>
68
                                <span id="facet-home-libraries">Home libraries</span>
74
                            [% END %]
69
                            [% CASE 'HoldingLibrary' %]
75
                            [% IF ( facets_loo.type_label_HoldingLibrary ) %]
76
                                <span id="facet-holding-libraries">Holding libraries</span>
70
                                <span id="facet-holding-libraries">Holding libraries</span>
77
                            [% END %]
71
                            [% CASE 'Location' %]
78
                            [% IF facets_loo.type_label_Location %]
79
                                <span id="facet-locations">Locations</span>
72
                                <span id="facet-locations">Locations</span>
80
                            [% END %]
73
                            [% CASE 'CollectionCodes' %]
81
                            [% IF facets_loo.type_label_CollectionCodes %]
82
                                <span id="facet-collections">Collections</span>
74
                                <span id="facet-collections">Collections</span>
83
                            [% END %]
75
                            [% CASE 'Languages' %]
84
                            [% IF facets_loo.type_label_Language %]
85
                                <span id="facet-languages">Languages</span>
76
                                <span id="facet-languages">Languages</span>
77
                            [% CASE %]
78
                                <span id="facet-[% facets_loo.type_link_value | html %]">[% facets_loo.label | html %]</span>
86
                            [% END %]
79
                            [% END %]
87
                            <ul>
80
                            <ul>
88
                                [% SET url = "/cgi-bin/koha/catalogue/search.pl?" _ query_cgi _ limit_cgi %]
81
                                [% SET url = "/cgi-bin/koha/catalogue/search.pl?" _ query_cgi _ limit_cgi %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-21 / +13 lines)
Lines 493-499 a.add, a.delete { Link Here
493
                                            <th>Order</th>
493
                                            <th>Order</th>
494
                                            <th class="NoSort">Search field</th>
494
                                            <th class="NoSort">Search field</th>
495
                                            <th class="NoSort">Label</th>
495
                                            <th class="NoSort">Label</th>
496
                                            <th class="NoSort">Display</th>
497
                                        </tr>
496
                                        </tr>
498
                                    </thead>
497
                                    </thead>
499
                                    <tbody>
498
                                    <tbody>
Lines 504-529 a.add, a.delete { Link Here
504
                                                    [% f.name | html %]
503
                                                    [% f.name | html %]
505
                                                </td>
504
                                                </td>
506
                                                <td>
505
                                                <td>
507
                                                    [% SWITCH f.name %]
506
                                                    [% SWITCH f.label %]
508
                                                    [% CASE 'author' %]<span>Authors</span>
507
                                                    [% CASE 'Authors' %]<span>Authors</span>
509
                                                    [% CASE 'itype' %]<span>Item types</span>
508
                                                    [% CASE 'Item types' %]<span>Item types</span>
510
                                                    [% CASE 'location' %]<span>Locations</span>
509
                                                    [% CASE 'Locations' %]<span>Locations</span>
511
                                                    [% CASE 'su-geo' %]<span>Places</span>
510
                                                    [% CASE 'Places' %]<span>Places</span>
512
                                                    [% CASE 'title-series' %]<span>Series</span>
511
                                                    [% CASE 'Series' %]<span>Series</span>
513
                                                    [% CASE 'subject' %]<span>Topics</span>
512
                                                    [% CASE 'Topics' %]<span>Topics</span>
514
                                                    [% CASE 'ccode' %]<span>Collections</span>
513
                                                    [% CASE 'Collections' %]<span>Collections</span>
515
                                                    [% CASE 'holdingbranch' %]<span>Holding libraries</span>
514
                                                    [% CASE 'Holding libraries' %]<span>Holding libraries</span>
516
                                                    [% CASE 'homebranch' %]<span>Home libraries</span>
515
                                                    [% CASE 'Home libraries' %]<span>Home libraries</span>
517
                                                    [% CASE 'ln' %]<span>Language</span>
516
                                                    [% CASE 'Languages' %]<span>Languages</span>
518
                                                    [% CASE %][% f | html %]
517
                                                    [% CASE %]<span>[% f.label | html %]</span>
519
                                                    [% END %]
520
                                                </td>
521
                                                <td>
522
                                                    [% IF f.facet_order %]
523
                                                        <input type="checkbox" name="display_facet" value="[% f.name | html %]" checked="checked" />
524
                                                    [% ELSE %]
525
                                                        <input type="checkbox" name="display_facet" value="[% f.name | html %]" />
526
                                                    [% END %]
518
                                                    [% END %]
519
                                                    <input type="hidden" name="facet_name" value="[% f.name | html %]" />
527
                                                </td>
520
                                                </td>
528
                                            </tr>
521
                                            </tr>
529
                                        [% END %]
522
                                        [% END %]
530
- 

Return to bug 35138