Bugzilla – Attachment 163133 Details for
Bug 35138
Enable configuration of facets with Elasticsearch
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35138: Make ES facetable fields configurable - POC
Bug-35138-Make-ES-facetable-fields-configurable---.patch (text/plain), 12.54 KB, created by
Jonathan Druart
on 2024-03-14 11:00:31 UTC
(
hide
)
Description:
Bug 35138: Make ES facetable fields configurable - POC
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2024-03-14 11:00:31 UTC
Size:
12.54 KB
patch
obsolete
>From 050710d78f03b8c615eb825756a9f3a1cc552f9d Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 14 Mar 2024 11:41:42 +0100 >Subject: [PATCH] Bug 35138: Make ES facetable fields configurable - POC > >Move the ES facet fields that are currently hardcoded in the codebase to a new >ES_FACETS authorised value category. > >Librarians can then add/remove facet fields and modify their lib/description. > >Remaining work: >1. Adjust OPAC templates >2. AV is not ideal here, we should certainly have a dedicated DB table for that. >It will bring more flexibility. >We can image: > * display or not (could be opac/staff/both/none) > * define the size per field (number of facet to display) > * order: move search_field.facet_order to this new table. In my > testing this is not worker, they are displayed alpha (??) >3. Adjust the UI > >Still no translatability however. >--- > C4/Search.pm | 1 + > Koha/SearchEngine/Elasticsearch.pm | 4 ++- > .../Elasticsearch/QueryBuilder.pm | 33 ++++++++--------- > Koha/SearchEngine/Elasticsearch/Search.pm | 27 +++++++------- > .../data/mysql/atomicupdate/bug_35138.pl | 30 ++++++++++++++++ > .../intranet-tmpl/prog/en/includes/facets.inc | 35 ++++++++----------- > 6 files changed, 78 insertions(+), 52 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug_35138.pl > >diff --git a/C4/Search.pm b/C4/Search.pm >index 248856e42b2..ea70377373f 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -579,6 +579,7 @@ sub getRecords { > "type_label_" > . $facets_info->{$link_value}->{'label_value'} => > 1, >+ label => $facets_info->{$link_value}->{'label_value'}, > facets => \@this_facets_array, > } > unless ( >diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm >index 3f26cbc0274..601ab50d257 100644 >--- a/Koha/SearchEngine/Elasticsearch.pm >+++ b/Koha/SearchEngine/Elasticsearch.pm >@@ -28,6 +28,7 @@ use Koha::Filter::MARC::EmbedSeeFromHeadings; > use Koha::SearchFields; > use Koha::SearchMarcMaps; > use Koha::Caches; >+use Koha::AuthorisedValueCategories; > use C4::Heading; > use C4::AuthoritiesMarc qw( GuessAuthTypeCode ); > use C4::Biblio; >@@ -1404,7 +1405,8 @@ 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 ); >+ my @search_field_names = Koha::AuthorisedValueCategories->find('ES_FACETS')->authorised_values->get_column('authorised_value'); > 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 35ab4b7f91d..224d1a245a4 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -48,6 +48,7 @@ use URI::Escape qw( uri_escape_utf8 ); > use C4::Context; > use Koha::Exceptions; > use Koha::Caches; >+use Koha::AuthorisedValueCategories; > > our %index_field_convert = ( > 'kw' => '', >@@ -225,26 +226,22 @@ sub build_query { > # See _convert_facets in Search.pm for how these get turned into > # things that Koha can use. > my $size = C4::Context->preference('FacetMaxCount'); >- $res->{aggregations} = { >- author => { terms => { field => "author__facet" , size => $size } }, >- subject => { terms => { field => "subject__facet", size => $size } }, >- itype => { terms => { field => "itype__facet", size => $size} }, >- location => { terms => { field => "location__facet", size => $size } }, >- 'su-geo' => { terms => { field => "su-geo__facet", size => $size} }, >- 'title-series' => { terms => { field => "title-series__facet", size => $size } }, >- ccode => { terms => { field => "ccode__facet", size => $size } }, >- ln => { terms => { field => "ln__facet", size => $size } }, >+ my @facets = Koha::AuthorisedValueCategories->find('ES_FACETS')->authorised_values->as_list; >+ for my $f ( @facets ) { >+ my $ff = $f->authorised_value; >+ $res->{aggregations}->{$ff} = { terms => { field => "${ff}__facet" , size => $size } }; > }; > >- 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", size => $size } }; >- } >- if ( $display_library_facets eq 'both' >- or $display_library_facets eq 'holding' ) { >- $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet", size => $size } }; >- } >+ # FIXME We need a way to show/hide the facet individually >+ #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", size => $size } }; >+ #} >+ #if ( $display_library_facets eq 'both' >+ # or $display_library_facets eq 'holding' ) { >+ # $res->{aggregations}{holdingbranch} = { terms => { field => "holdingbranch__facet", size => $size } }; >+ #} > return $res; > } > >diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm >index 933b52f79dd..c0fe227d891 100644 >--- a/Koha/SearchEngine/Elasticsearch/Search.pm >+++ b/Koha/SearchEngine/Elasticsearch/Search.pm >@@ -45,6 +45,7 @@ use C4::Context; > use C4::AuthoritiesMarc; > use Koha::ItemTypes; > use Koha::AuthorisedValues; >+use Koha::AuthorisedValueCategories; > use Koha::SearchEngine::QueryBuilder; > use Koha::SearchEngine::Search; > use Koha::Exceptions::Elasticsearch; >@@ -443,18 +444,19 @@ sub _convert_facets { > # These should correspond to the ES field names, as opposed to the CCL > # things that zebra uses. > my %type_to_label; >- my %label = ( >- author => 'Authors', >- itype => 'ItemTypes', >- location => 'Location', >- 'su-geo' => 'Places', >- 'title-series' => 'Series', >- subject => 'Topics', >- ccode => 'CollectionCodes', >- holdingbranch => 'HoldingLibrary', >- homebranch => 'HomeLibrary', >- ln => 'Language', >- ); >+ #my %label = ( >+ # author => 'Authors', >+ # itype => 'ItemTypes', >+ # location => 'Location', >+ # 'su-geo' => 'Places', >+ # 'title-series' => 'Series', >+ # subject => 'Topics', >+ # ccode => 'CollectionCodes', >+ # holdingbranch => 'HoldingLibrary', >+ # homebranch => 'HomeLibrary', >+ # ln => 'Language', >+ #); >+ my %label = map {$_->authorised_value => $_->lib } Koha::AuthorisedValueCategories->find('ES_FACETS')->authorised_values->as_list; > my @facetable_fields = > Koha::SearchEngine::Elasticsearch->get_facetable_fields; > for my $f (@facetable_fields) { >@@ -486,6 +488,7 @@ sub _convert_facets { > my $facet = { > type_id => $type . '_id', > "type_label_$type_to_label{$type}{label}" => 1, >+ label => $type_to_label{$type}{label}, > type_link_value => $type, > order => $type_to_label{$type}{order}, > }; >diff --git a/installer/data/mysql/atomicupdate/bug_35138.pl b/installer/data/mysql/atomicupdate/bug_35138.pl >new file mode 100755 >index 00000000000..19f579d76d3 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_35138.pl >@@ -0,0 +1,30 @@ >+use Modern::Perl; >+ >+return { >+ bug_number => "35138", >+ description => "Add ES_FACETS AV cat", >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ >+ $dbh->do(q{INSERT IGNORE INTO authorised_value_categories(category_name, is_system) VALUES('ES_FACETS', 1)}); >+ my $sth = $dbh->prepare( >+ q{INSERT IGNORE INTO authorised_values(category, authorised_value, lib) VALUES('ES_FACETS', ?, ?)}); >+ >+ my $facets = { >+ author => 'Authors', >+ itype => 'ItemTypes', >+ location => 'Location', >+ 'su-geo' => 'Places', >+ 'title-series' => 'Series', >+ subject => 'Topics', >+ ccode => 'CollectionCodes', >+ holdingbranch => 'HoldingLibrary', >+ homebranch => 'HomeLibrary', >+ ln => 'Language', >+ }; >+ while ( my ( $av, $lib ) = each %$facets ) { >+ $sth->execute( $av, $lib ); >+ } >+ }, >+}; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc >index 2fcce67e7d2..6bb127fa729 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/facets.inc >@@ -51,38 +51,31 @@ > [% IF facets_loo.facets.size > 0 %] > <li id="[% facets_loo.type_id | html %]"> > [% facets_loo.type_label | html %] >- [% IF facets_loo.type_label_Authors %] >+ [% SWITCH facets_loo.label %] >+ [% CASE 'Authors' %] > <span id="facet-authors">Authors</span> >- [% END %] >- [% IF facets_loo.type_label_Titles %] >+ [% CASE 'Titles' %] > <span id="facet-titles">Titles</span> >- [% END %] >- [% IF facets_loo.type_label_Topics %] >+ [% CASE 'Topics' %] > <span id="facet-topics">Topics</span> >- [% END %] >- [% IF facets_loo.type_label_Places %] >+ [% CASE 'Places' %] > <span id="facet-places">Places</span> >- [% END %] >- [% IF facets_loo.type_label_Series %] >+ [% CASE 'Series' %] > <span id="facet-series">Series</span> >- [% END %] >- [% IF facets_loo.type_label_ItemTypes %] >+ [% CASE 'ItemTypes' %] > <span id="facet-itemtypes">Item types</span> >- [% END %] >- [% IF ( facets_loo.type_label_HomeLibrary ) %] >+ [% CASE 'HomeLibrary' %] > <span id="facet-home-libraries">Home libraries</span> >- [% END %] >- [% IF ( facets_loo.type_label_HoldingLibrary ) %] >+ [% CASE 'HoldingLibrary' %] > <span id="facet-holding-libraries">Holding libraries</span> >- [% END %] >- [% IF facets_loo.type_label_Location %] >+ [% CASE 'Location' %] > <span id="facet-locations">Locations</span> >- [% END %] >- [% IF facets_loo.type_label_CollectionCodes %] >+ [% CASE 'CollectionCodes' %] > <span id="facet-collections">Collections</span> >- [% END %] >- [% IF facets_loo.type_label_Language %] >+ [% CASE 'Languages' %] > <span id="facet-languages">Languages</span> >+ [% CASE %] >+ <span id="facet-[% facets_loo.type_link_value | html %]">[% facets_loo.label | html %]</span> > [% END %] > <ul> > [% SET url = "/cgi-bin/koha/catalogue/search.pl?" _ query_cgi _ limit_cgi %] >-- >2.34.1
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 35138
:
163133
|
163680
|
163681
|
163682
|
163683
|
163684
|
163896
|
163897
|
163898
|
163899
|
163900
|
164811
|
164812
|
164813
|
164814
|
164815
|
164816
|
165811
|
165812
|
165813
|
165814
|
165815
|
165816
|
165817
|
165818
|
166402