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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-1 / +11 lines)
Lines 115-124 sub build_query { Link Here
115
        author   => { terms => { field => "author__facet" } },
115
        author   => { terms => { field => "author__facet" } },
116
        subject  => { terms => { field => "subject__facet" } },
116
        subject  => { terms => { field => "subject__facet" } },
117
        itype    => { terms => { field => "itype__facet" } },
117
        itype    => { terms => { field => "itype__facet" } },
118
        location => { terms => { field => "homebranch__facet" } },
118
        location => { terms => { field => "location__facet" } },
119
        'su-geo' => { terms => { field => "su-geo__facet" } },
119
        'su-geo' => { terms => { field => "su-geo__facet" } },
120
        se       => { terms => { field => "se__facet" } },
120
        se       => { terms => { field => "se__facet" } },
121
    };
121
    };
122
123
    my $display_library_facets = C4::Context->preference('DisplayLibraryFacets');
124
    if (   $display_library_facets eq 'both'
125
        or $display_library_facets eq 'home' ) {
126
        $res->{aggregations}{homebranch} = { terms => { field => "homebranch__facet" } };
127
    }
128
    if (   $display_library_facets eq 'both'
129
        or $display_library_facets eq 'holding' ) {
130
        $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet" } };
131
    }
122
    if ( my $ef = $options{expanded_facet} ) {
132
    if ( my $ef = $options{expanded_facet} ) {
123
        $res->{aggregations}{$ef}{terms}{size} = C4::Context->preference('FacetMaxCount');
133
        $res->{aggregations}{$ef}{terms}{size} = C4::Context->preference('FacetMaxCount');
124
    };
134
    };
(-)a/Koha/SearchEngine/Elasticsearch/Search.pm (+6 lines)
Lines 408-423 sub _convert_facets { Link Here
408
        'su-geo' => { order => 4, label => 'Places', },
408
        'su-geo' => { order => 4, label => 'Places', },
409
        se       => { order => 5, label => 'Series', },
409
        se       => { order => 5, label => 'Series', },
410
        subject  => { order => 6, label => 'Topics', },
410
        subject  => { order => 6, label => 'Topics', },
411
        holdingbranch => { order => 8, label => 'HoldingLibrary' },
412
        homebranch => { order => 9, label => 'HomeLibrary' }
411
    );
413
    );
412
414
413
    # We also have some special cases, e.g. itypes that need to show the
415
    # We also have some special cases, e.g. itypes that need to show the
414
    # value rather than the code.
416
    # value rather than the code.
415
    my @itypes = Koha::ItemTypes->search;
417
    my @itypes = Koha::ItemTypes->search;
418
    my @libraries = Koha::Libraries->search;
419
    my $library_names = { map { $_->branchcode => $_->branchname } @libraries };
416
    my @locations = Koha::AuthorisedValues->search( { category => 'LOC' } );
420
    my @locations = Koha::AuthorisedValues->search( { category => 'LOC' } );
417
    my $opac = C4::Context->interface eq 'opac' ;
421
    my $opac = C4::Context->interface eq 'opac' ;
418
    my %special = (
422
    my %special = (
419
        itype    => { map { $_->itemtype         => $_->description } @itypes },
423
        itype    => { map { $_->itemtype         => $_->description } @itypes },
420
        location => { map { $_->authorised_value => ( $opac ? ( $_->lib_opac || $_->lib ) : $_->lib ) } @locations },
424
        location => { map { $_->authorised_value => ( $opac ? ( $_->lib_opac || $_->lib ) : $_->lib ) } @locations },
425
        holdingbranch => $library_names,
426
        homebranch => $library_names
421
    );
427
    );
422
    my @facets;
428
    my @facets;
423
    $exp_facet //= '';
429
    $exp_facet //= '';
(-)a/admin/searchengine/elasticsearch/mappings.yaml (-4 / +23 lines)
Lines 1425-1438 biblios: Link Here
1425
        suggestible: ''
1425
        suggestible: ''
1426
    type: ''
1426
    type: ''
1427
  holdingbranch:
1427
  holdingbranch:
1428
    label: holdingbranch
1428
    label: HoldingLibrary
1429
    mappings:
1429
    mappings:
1430
      - facet: ''
1430
      - facet: '1'
1431
        marc_field: 952b
1431
        marc_field: 952b
1432
        marc_type: marc21
1432
        marc_type: marc21
1433
        sort: ~
1433
        sort: ~
1434
        suggestible: ''
1434
        suggestible: ''
1435
      - facet: ''
1435
      - facet: '1'
1436
        marc_field: 952b
1436
        marc_field: 952b
1437
        marc_type: normarc
1437
        marc_type: normarc
1438
        sort: ~
1438
        sort: ~
Lines 1444-1450 biblios: Link Here
1444
        suggestible: ''
1444
        suggestible: ''
1445
    type: string
1445
    type: string
1446
  homebranch:
1446
  homebranch:
1447
    label: homebranch
1447
    label: HomeLibrary
1448
    mappings:
1448
    mappings:
1449
      - facet: '1'
1449
      - facet: '1'
1450
        marc_field: 952a
1450
        marc_field: 952a
Lines 1736-1741 biblios: Link Here
1736
        sort: ~
1736
        sort: ~
1737
        suggestible: '1'
1737
        suggestible: '1'
1738
    type: ''
1738
    type: ''
1739
  location:
1740
    label: Location
1741
    mappings:
1742
      - facet: '1'
1743
        marc_field: 952c
1744
        marc_type: marc21
1745
        sort: ~
1746
        suggestible: ''
1747
      - facet: '1'
1748
        marc_field: 952c
1749
        marc_type: normarc
1750
        sort: ~
1751
        suggestible: ''
1752
      - facet: '1'
1753
        marc_field: 995e
1754
        marc_type: unimarc
1755
        sort: ~
1756
        suggestible: ''
1757
    type: ''
1739
  material-type:
1758
  material-type:
1740
    label: material-type
1759
    label: material-type
1741
    mappings:
1760
    mappings:
(-)a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t (-2 / +25 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 11;
20
use Test::More tests => 12;
21
use t::lib::Mocks;
21
22
22
use Koha::SearchEngine::Elasticsearch::QueryBuilder;
23
use Koha::SearchEngine::Elasticsearch::QueryBuilder;
23
24
Lines 79-82 subtest 'json2marc' => sub { Link Here
79
80
80
};
81
};
81
82
83
subtest 'build_query tests' => sub {
84
    plan tests => 6;
85
86
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
87
    my $query = $builder->build_query();
88
    ok( defined $query->{aggregations}{homebranch},
89
        'homebranch added to facets if DisplayLibraryFacets=both' );
90
    ok( defined $query->{aggregations}{holdingbranch},
91
        'holdingbranch added to facets if DisplayLibraryFacets=both' );
92
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','holding');
93
    $query = $builder->build_query();
94
    ok( !defined $query->{aggregations}{homebranch},
95
        'homebranch not added to facets if DisplayLibraryFacets=holding' );
96
    ok( defined $query->{aggregations}{holdingbranch},
97
        'holdingbranch added to facets if DisplayLibraryFacets=holding' );
98
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','home');
99
    $query = $builder->build_query();
100
    ok( defined $query->{aggregations}{homebranch},
101
        'homebranch added to facets if DisplayLibraryFacets=home' );
102
    ok( !defined $query->{aggregations}{holdingbranch},
103
        'holdingbranch not added to facets if DisplayLibraryFacets=home' );
104
};
105
82
1;
106
1;
83
- 

Return to bug 18068