Bugzilla – Attachment 147769 Details for
Bug 33139
New facetable boolean Elasticsearch field 'has-eresource'.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33139 Added "has e-resource" facet for Elasticsearch
Bug-33139-Added-has-e-resource-facet-for-Elasticse.patch (text/plain), 7.97 KB, created by
Andreas Jonsson
on 2023-03-05 11:51:29 UTC
(
hide
)
Description:
Bug 33139 Added "has e-resource" facet for Elasticsearch
Filename:
MIME Type:
Creator:
Andreas Jonsson
Created:
2023-03-05 11:51:29 UTC
Size:
7.97 KB
patch
obsolete
>From 62ee0a0f86b31cc65f473281c40e041651864311 Mon Sep 17 00:00:00 2001 >From: Andreas Jonsson <andreas.jonsson@kreablo.se> >Date: Fri, 3 Mar 2023 15:43:38 +0100 >Subject: [PATCH] Bug 33139 Added "has e-resource" facet for Elasticsearch > >--- > Koha/SearchEngine/Elasticsearch.pm | 5 ++++- > Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 1 + > Koha/SearchEngine/Elasticsearch/Search.pm | 11 ++++++++--- > koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc | 12 ++++++++++++ > .../admin/searchengine/elasticsearch/mappings.tt | 2 ++ > .../opac-tmpl/bootstrap/en/includes/opac-facets.inc | 12 ++++++++++++ > 6 files changed, 39 insertions(+), 4 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index 1fe6fb1c6f..8ccf51e560 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -1056,6 +1056,9 @@ sub _get_marc_mapping_rules { > # boolean gets special handling, if value doesn't exist for a field, > # it is set to false > $rules->{defaults}->{$name} = 'false'; >+ if ($facet) { >+ $rules->{defaults}->{"${name}__facet"} = 'false'; >+ } > } > > if ($marc_field =~ $field_spec_regexp) { >@@ -1369,7 +1372,7 @@ sub get_facetable_fields { > > # These should correspond to the ES field names, as opposed to the CCL > # things that zebra uses. >- my @search_field_names = qw( author itype location su-geo title-series subject ccode holdingbranch homebranch ln ); >+ my @search_field_names = qw( author itype location su-geo title-series subject ccode holdingbranch homebranch ln has-eresource only-print ); > my @faceted_fields = Koha::SearchFields->search( > { name => { -in => \@search_field_names }, facet_order => { '!=' => undef } }, { order_by => ['facet_order'] } > )->as_list; >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 53042b4303..6c8508a5c5 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -233,6 +233,7 @@ sub build_query { > 'title-series' => { terms => { field => "title-series__facet", size => $size } }, > ccode => { terms => { field => "ccode__facet", size => $size } }, > ln => { terms => { field => "ln__facet", size => $size } }, >+ 'has-eresource' => { terms => { field => "has-eresource__facet", size => $size } } > }; > > my $display_library_facets = C4::Context->preference('DisplayLibraryFacets'); >diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm >index e8e4412b56..aefa99b4d9 100644 >--- a/Koha/SearchEngine/Elasticsearch/Search.pm >+++ b/Koha/SearchEngine/Elasticsearch/Search.pm >@@ -454,10 +454,13 @@ sub _convert_facets { > holdingbranch => 'HoldingLibrary', > homebranch => 'HomeLibrary', > ln => 'Language', >+ 'has-eresource' => 'HasEresource', >+ 'only-print' => 'OnlyPrint' > ); > my @facetable_fields = >- Koha::SearchEngine::Elasticsearch->get_facetable_fields; >- for my $f (@facetable_fields) { >+ Koha::SearchEngine::Elasticsearch->get_facetable_fields; >+ >+ for my $f (@facetable_fields) { > next unless defined $f->facet_order; > $type_to_label{ $f->name } = > { order => $f->facet_order, label => $label{ $f->name } }; >@@ -495,7 +498,9 @@ sub _convert_facets { > next unless length($t); # FIXME Currently we cannot search for an empty faceted field i.e. ln:"" to find records missing languages, though ES does count them correctly > my $c = $term->{doc_count}; > my $label; >- if ( exists( $special{$type} ) ) { >+ if ($type eq 'has-eresource') { >+ $t = $t && $t ne 'false' ? 'true' : 'false'; >+ } elsif ( exists( $special{$type} ) ) { > $label = $special{$type}->{$t} // $t; > } > else { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc >index 2c56036f04..9143911873 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc >@@ -43,6 +43,18 @@ > [% IF facets_loo.type_label_Location %]<span id="facet-locations">Locations</span>[% END %] > [% IF facets_loo.type_label_CollectionCodes %]<span id="facet-collections">Collections</span>[% END %] > [% IF facets_loo.type_label_Language %]<span id="facet-languages">Languages</span>[% END %] >+[% IF facets_loo.type_label_HasEresource %]<span id="facet-has-eresource">E-resource</span> >+ [%- FOREACH facet IN facets_loo.facets %] >+ [% facet.facet_label_value = BLOCK %] >+ [%- IF facet.facet_link_value == 'true' -%] >+ <p>Digitally available</p> >+ [%- ELSE -%] >+ <p>Only in print</p> >+ [%- END %] >+ [% END %] >+ [% facet.facet_label_value = facet.facet_label_value | remove('</?p>') %] >+ [% END %] >+[% END %] > <ul> > [% SET url = "/cgi-bin/koha/catalogue/search.pl?" _ query_cgi _ limit_cgi %] > [% IF ( sort_by ) %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt >index b0ec83750f..095e8433e4 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt >@@ -460,6 +460,8 @@ a.add, a.delete { > [% CASE 'holdingbranch' %]<span>Holding libraries</span> > [% CASE 'homebranch' %]<span>Home libraries</span> > [% CASE 'ln' %]<span>Language</span> >+ [% CASE 'has-eresource' %]<span>Has eresource</span> >+ [% CASE 'only-print' %]<span>Only print</span> > [% CASE %][% f | html %] > [% END %] > </td> >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc >index 844de90853..8619a5a5e2 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-facets.inc >@@ -46,6 +46,18 @@ > [% IF facets_loo.type_label_ItemTypes %]<h3 id="facet-itemtypes">Item types</h3>[% END %] > [% IF facets_loo.type_label_CollectionCodes %]<h3 id="facet-collections">Collections</h3>[% END %] > [% IF facets_loo.type_label_Language %]<h3 id="facet-languages">Languages</h3>[% END %] >+ [% IF facets_loo.type_label_HasEresource %]<h3 id="facet-has-eresource">E-resource</h3> >+ [%- FOREACH facet IN facets_loo.facets %] >+ [% facet.facet_label_value = BLOCK %] >+ [%- IF facet.facet_link_value == 'true' -%] >+ <p>Digitally available</p> >+ [%- ELSE -%] >+ <p>Only in print</p> >+ [%- END -%] >+ [% END %] >+ [% facet.facet_label_value = facet.facet_label_value | remove('</?p>') %] >+ [% END %] >+ [% END %] > [% UNLESS singleBranchMode %] > [% IF ( facets_loo.type_label_HomeLibrary ) %]<h3 id="facet-home-libraries">Home libraries</h3>[% END %] > [% IF ( facets_loo.type_label_HoldingLibrary ) %]<h3 id="facet-holding-libraries">Holding libraries</h3>[% END %] >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33139
: 147769 |
147770
|
147771
|
147772