author => { terms => { field => "author__facet" } },
subject => { terms => { field => "subject__facet" } },
itype => { terms => { field => "itype__facet" } },
- location => { terms => { field => "homebranch__facet" } },
+ location => { terms => { field => "location__facet" } },
'su-geo' => { terms => { field => "su-geo__facet" } },
se => { terms => { field => "se__facet" } },
};
+
+ my $display_library_facets = C4::Context->preference('DisplayLibraryFacets');
+ if ( $display_library_facets eq 'both'
+ or $display_library_facets eq 'home' ) {
+ $res->{aggregations}{homebranch} = { terms => { field => "homebranch__facet" } };
+ }
+ if ( $display_library_facets eq 'both'
+ or $display_library_facets eq 'holding' ) {
+ $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet" } };
+ }
if ( my $ef = $options{expanded_facet} ) {
$res->{aggregations}{$ef}{terms}{size} = C4::Context->preference('FacetMaxCount');
};
'su-geo' => { order => 4, label => 'Places', },
se => { order => 5, label => 'Series', },
subject => { order => 6, label => 'Topics', },
+ holdingbranch => { order => 8, label => 'HoldingLibrary' },
+ homebranch => { order => 9, label => 'HomeLibrary' }
);
# We also have some special cases, e.g. itypes that need to show the
# value rather than the code.
my @itypes = Koha::ItemTypes->search;
+ my @libraries = Koha::Libraries->search;
+ my $library_names = { map { $_->branchcode => $_->branchname } @libraries };
my @locations = Koha::AuthorisedValues->search( { category => 'LOC' } );
my $opac = C4::Context->interface eq 'opac' ;
my %special = (
itype => { map { $_->itemtype => $_->description } @itypes },
location => { map { $_->authorised_value => ( $opac ? ( $_->lib_opac || $_->lib ) : $_->lib ) } @locations },
+ holdingbranch => $library_names,
+ homebranch => $library_names
);
my @facets;
$exp_facet //= '';
suggestible: ''
type: ''
holdingbranch:
- label: holdingbranch
+ label: HoldingLibrary
mappings:
- - facet: ''
+ - facet: '1'
marc_field: 952b
marc_type: marc21
sort: ~
suggestible: ''
- - facet: ''
+ - facet: '1'
marc_field: 952b
marc_type: normarc
sort: ~
suggestible: ''
type: string
homebranch:
- label: homebranch
+ label: HomeLibrary
mappings:
- facet: '1'
marc_field: 952a
sort: ~
suggestible: '1'
type: ''
+ location:
+ label: Location
+ mappings:
+ - facet: '1'
+ marc_field: 952c
+ marc_type: marc21
+ sort: ~
+ suggestible: ''
+ - facet: '1'
+ marc_field: 952c
+ marc_type: normarc
+ sort: ~
+ suggestible: ''
+ - facet: '1'
+ marc_field: 995e
+ marc_type: unimarc
+ sort: ~
+ suggestible: ''
+ type: ''
material-type:
label: material-type
mappings:
use Modern::Perl;
-use Test::More tests => 11;
+use Test::More tests => 12;
+use t::lib::Mocks;
use Koha::SearchEngine::Elasticsearch::QueryBuilder;
};
+subtest 'build_query tests' => sub {
+ plan tests => 6;
+
+ t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
+ my $query = $builder->build_query();
+ ok( defined $query->{aggregations}{homebranch},
+ 'homebranch added to facets if DisplayLibraryFacets=both' );
+ ok( defined $query->{aggregations}{holdingbranch},
+ 'holdingbranch added to facets if DisplayLibraryFacets=both' );
+ t::lib::Mocks::mock_preference('DisplayLibraryFacets','holding');
+ $query = $builder->build_query();
+ ok( !defined $query->{aggregations}{homebranch},
+ 'homebranch not added to facets if DisplayLibraryFacets=holding' );
+ ok( defined $query->{aggregations}{holdingbranch},
+ 'holdingbranch added to facets if DisplayLibraryFacets=holding' );
+ t::lib::Mocks::mock_preference('DisplayLibraryFacets','home');
+ $query = $builder->build_query();
+ ok( defined $query->{aggregations}{homebranch},
+ 'homebranch added to facets if DisplayLibraryFacets=home' );
+ ok( !defined $query->{aggregations}{holdingbranch},
+ 'holdingbranch not added to facets if DisplayLibraryFacets=home' );
+};
+
1;