From c877425e2cd02eca921ec42865a56be7761de809 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Tue, 11 Oct 2016 09:01:12 +0000 Subject: [PATCH] Bug 17169 - Add a facet for ccode fields to ElasticSearch To test: 1 - Apply patch 2 - Backup your db 3 - Drop and create a new db to ensure your mappings are refreshed from the patch 4 - add some titles with items with collection codes 5 - search and see collection code facets 6 - sign off Work to be done: 1 - Replace codes with descriptions --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 1 + Koha/SearchEngine/Elasticsearch/Search.pm | 2 +- admin/searchengine/elasticsearch/mappings.yaml | 9 +++++++++ koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc | 1 + koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc | 1 + 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 46609c0..b2a65ac 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -118,6 +118,7 @@ sub build_query { location => { terms => { field => "homebranch__facet" } }, 'su-geo' => { terms => { field => "su-geo__facet" } }, se => { terms => { field => "se__facet" } }, + ccode => { terms => { field => "ccode__facet" } }, }; if ( my $ef = $options{expanded_facet} ) { $res->{facets}{$ef}{terms}{size} = C4::Context->preference('FacetMaxCount'); diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 212a561..9612723 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -146,7 +146,6 @@ sub search_compat { $servers, $results_per_page, $offset, $expanded_facet, $branches, $query_type, $scan ) = @_; - my %options; $options{offset} = $offset; $options{expanded_facet} = $expanded_facet; @@ -400,6 +399,7 @@ sub _convert_facets { 'su-geo' => { order => 4, label => 'Places', }, se => { order => 5, label => 'Series', }, subject => { order => 6, label => 'Topics', }, + ccode => { order => 7, label => 'CollectionCodes',}, ); # We also have some special cases, e.g. itypes that need to show the diff --git a/admin/searchengine/elasticsearch/mappings.yaml b/admin/searchengine/elasticsearch/mappings.yaml index b56e2b4..fa3c8f8 100644 --- a/admin/searchengine/elasticsearch/mappings.yaml +++ b/admin/searchengine/elasticsearch/mappings.yaml @@ -1255,6 +1255,15 @@ biblios: sort: ~ suggestible: '' type: '' + ccode: + label: collection-code + mappings: + - facet: '1' + marc_field: '9528' + marc_type: marc21 + sort: ~ + suggestible: '' + type: '' control-number: label: control-number mappings: diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc index 3d0d15e..887c38c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc @@ -20,6 +20,7 @@ [% IF ( facets_loo.type_label_HomeLibrary ) %]Home libraries[% END %] [% IF ( facets_loo.type_label_HoldingLibrary ) %]Holding libraries[% END %] [% IF facets_loo.type_label_Location %]Locations[% END %] +[% IF facets_loo.type_label_CollectionCodes %]Collections[% END %]