From 957a13595e940377cc26c9cf66257f93dbb62d1a Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 12 Nov 2020 10:11:33 +0100 Subject: [PATCH] Bug 25054: Display search field aliases in Search Engine Configuration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit It'd be great if the Search Engine Configuration page would display the various aliases (shortcuts) available : ti for title, sn for local-number, etc. Patch changes Koha/SearchEngine/Elasticsearch/QueryBuilder.pm to move hard-coded vars at the beging and adds a method to provide to %index_field_convert via a method. Test plan : 1) Use Elasticsearch 2) Go to Administration > Search engine configuration (Elasticsearch) 3) Check you see new column 'Aliases' with for example ti for title. 4) Perform a search 'ti:' and check you get results Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> (cherry picked from commit fd8aee927005f27fb10ed8944afbbd318e610dfb) Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com> --- .../Elasticsearch/QueryBuilder.pm | 206 +++++++++--------- admin/searchengine/elasticsearch/mappings.pl | 10 + .../searchengine/elasticsearch/mappings.tt | 6 +- 3 files changed, 120 insertions(+), 102 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 06a765d386..d551ad93c1 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -50,6 +50,111 @@ use C4::Context; use Koha::Exceptions; use Koha::Caches; +our %index_field_convert = ( + 'kw' => '', + 'ab' => 'abstract', + 'au' => 'author', + 'lcn' => 'local-classification', + 'callnum' => 'local-classification', + 'record-type' => 'rtype', + 'mc-rtype' => 'rtype', + 'mus' => 'rtype', + 'lc-card' => 'lc-card-number', + 'sn' => 'local-number', + 'biblionumber' => 'local-number', + 'yr' => 'date-of-publication', + 'pubdate' => 'date-of-publication', + 'acqdate' => 'date-of-acquisition', + 'date/time-last-modified' => 'date-time-last-modified', + 'dtlm' => 'date-time-last-modified', + 'diss' => 'dissertation-information', + 'nb' => 'isbn', + 'ns' => 'issn', + 'music-number' => 'identifier-publisher-for-music', + 'number-music-publisher' => 'identifier-publisher-for-music', + 'music' => 'identifier-publisher-for-music', + 'ident' => 'identifier-standard', + 'cpn' => 'corporate-name', + 'cfn' => 'conference-name', + 'pn' => 'personal-name', + 'pb' => 'publisher', + 'pv' => 'provider', + 'nt' => 'note', + 'notes' => 'note', + 'rcn' => 'record-control-number', + 'su' => 'subject', + 'su-to' => 'subject', + #'su-geo' => 'subject', + 'su-ut' => 'subject', + 'ti' => 'title', + 'se' => 'title-series', + 'ut' => 'title-uniform', + 'an' => 'koha-auth-number', + 'authority-number' => 'koha-auth-number', + 'at' => 'authtype', + 'he' => 'heading', + 'rank' => 'relevance', + 'phr' => 'st-phrase', + 'wrdl' => 'st-word-list', + 'rt' => 'right-truncation', + 'rtrn' => 'right-truncation', + 'ltrn' => 'left-truncation', + 'rltrn' => 'left-and-right', + 'mc-itemtype' => 'itemtype', + 'mc-ccode' => 'ccode', + 'branch' => 'homebranch', + 'mc-loc' => 'location', + 'loc' => 'location', + 'stocknumber' => 'number-local-acquisition', + 'inv' => 'number-local-acquisition', + 'bc' => 'barcode', + 'mc-itype' => 'itype', + 'aub' => 'author-personal-bibliography', + 'auo' => 'author-in-order', + 'ff8-22' => 'ta', + 'aud' => 'ta', + 'audience' => 'ta', + 'frequency-code' => 'ff8-18', + 'illustration-code' => 'ff8-18-21', + 'regularity-code' => 'ff8-19', + 'type-of-serial' => 'ff8-21', + 'format' => 'ff8-23', + 'conference-code' => 'ff8-29', + 'festschrift-indicator' => 'ff8-30', + 'index-indicator' => 'ff8-31', + 'fiction' => 'lf', + 'fic' => 'lf', + 'literature-code' => 'lf', + 'biography' => 'bio', + 'ff8-34' => 'bio', + 'biography-code' => 'bio', + 'l-format' => 'ff7-01-02', + 'lex' => 'lexile-number', + 'hi' => 'host-item-number', + 'itu' => 'index-term-uncontrolled', + 'itg' => 'index-term-genre', +); +my $field_name_pattern = '[\w\-]+'; +my $multi_field_pattern = "(?:\\.$field_name_pattern)*"; + +=head2 get_index_field_convert + + my @index_params = Koha::SearchEngine::Elasticsearch::QueryBuilder->get_index_field_convert(); + +Converts zebra-style search index notation into elasticsearch-style. + +C<@indexes> is an array of index names, as presented to L<build_query_compat>, +and it returns something that can be sent to L<build_query>. + +B<TODO>: this will pull from the elasticsearch mappings table to figure out +types. + +=cut + +sub get_index_field_convert() { + return \%index_field_convert; +} + =head2 build_query my $simple_query = $builder->build_query("hello", %options) @@ -608,107 +713,6 @@ sub _convert_sort_fields { } @sort_by; } -=head2 _convert_index_fields - - my @index_params = $self->_convert_index_fields(@indexes); - -Converts zebra-style search index notation into elasticsearch-style. - -C<@indexes> is an array of index names, as presented to L<build_query_compat>, -and it returns something that can be sent to L<build_query>. - -B<TODO>: this will pull from the elasticsearch mappings table to figure out -types. - -=cut - -our %index_field_convert = ( - 'kw' => '', - 'ab' => 'abstract', - 'au' => 'author', - 'lcn' => 'local-classification', - 'callnum' => 'local-classification', - 'record-type' => 'rtype', - 'mc-rtype' => 'rtype', - 'mus' => 'rtype', - 'lc-card' => 'lc-card-number', - 'sn' => 'local-number', - 'biblionumber' => 'local-number', - 'yr' => 'date-of-publication', - 'pubdate' => 'date-of-publication', - 'acqdate' => 'date-of-acquisition', - 'date/time-last-modified' => 'date-time-last-modified', - 'dtlm' => 'date-time-last-modified', - 'diss' => 'dissertation-information', - 'nb' => 'isbn', - 'ns' => 'issn', - 'music-number' => 'identifier-publisher-for-music', - 'number-music-publisher' => 'identifier-publisher-for-music', - 'music' => 'identifier-publisher-for-music', - 'ident' => 'identifier-standard', - 'cpn' => 'corporate-name', - 'cfn' => 'conference-name', - 'pn' => 'personal-name', - 'pb' => 'publisher', - 'pv' => 'provider', - 'nt' => 'note', - 'notes' => 'note', - 'rcn' => 'record-control-number', - 'su' => 'subject', - 'su-to' => 'subject', - #'su-geo' => 'subject', - 'su-ut' => 'subject', - 'ti' => 'title', - 'se' => 'title-series', - 'ut' => 'title-uniform', - 'an' => 'koha-auth-number', - 'authority-number' => 'koha-auth-number', - 'at' => 'authtype', - 'he' => 'heading', - 'rank' => 'relevance', - 'phr' => 'st-phrase', - 'wrdl' => 'st-word-list', - 'rt' => 'right-truncation', - 'rtrn' => 'right-truncation', - 'ltrn' => 'left-truncation', - 'rltrn' => 'left-and-right', - 'mc-itemtype' => 'itemtype', - 'mc-ccode' => 'ccode', - 'branch' => 'homebranch', - 'mc-loc' => 'location', - 'loc' => 'location', - 'stocknumber' => 'number-local-acquisition', - 'inv' => 'number-local-acquisition', - 'bc' => 'barcode', - 'mc-itype' => 'itype', - 'aub' => 'author-personal-bibliography', - 'auo' => 'author-in-order', - 'ff8-22' => 'ta', - 'aud' => 'ta', - 'audience' => 'ta', - 'frequency-code' => 'ff8-18', - 'illustration-code' => 'ff8-18-21', - 'regularity-code' => 'ff8-19', - 'type-of-serial' => 'ff8-21', - 'format' => 'ff8-23', - 'conference-code' => 'ff8-29', - 'festschrift-indicator' => 'ff8-30', - 'index-indicator' => 'ff8-31', - 'fiction' => 'lf', - 'fic' => 'lf', - 'literature-code' => 'lf', - 'biography' => 'bio', - 'ff8-34' => 'bio', - 'biography-code' => 'bio', - 'l-format' => 'ff7-01-02', - 'lex' => 'lexile-number', - 'hi' => 'host-item-number', - 'itu' => 'index-term-uncontrolled', - 'itg' => 'index-term-genre', -); -my $field_name_pattern = '[\w\-]+'; -my $multi_field_pattern = "(?:\\.$field_name_pattern)*"; - sub _convert_index_fields { my ( $self, @indexes ) = @_; diff --git a/admin/searchengine/elasticsearch/mappings.pl b/admin/searchengine/elasticsearch/mappings.pl index e43c7a8516..96c6853576 100755 --- a/admin/searchengine/elasticsearch/mappings.pl +++ b/admin/searchengine/elasticsearch/mappings.pl @@ -24,6 +24,7 @@ use C4::Output; use C4::Auth; use Koha::SearchEngine::Elasticsearch; +use Koha::SearchEngine::Elasticsearch::QueryBuilder; use Koha::SearchMarcMaps; use Koha::SearchFields; use Koha::Caches; @@ -77,6 +78,14 @@ my $update_mappings = sub { } }; +my $search_fields_aliases = {}; +while ( my ( $key, $value ) = each(%{Koha::SearchEngine::Elasticsearch::QueryBuilder->get_index_field_convert}) ) { + my $field_aliases = $search_fields_aliases->{$value}; + $field_aliases = [] unless $field_aliases; + push @$field_aliases, $key; + $search_fields_aliases->{$value} = $field_aliases; +} + if ( $op eq 'edit' ) { $schema->storage->txn_begin; @@ -260,6 +269,7 @@ my @all_search_fields; while ( my $search_field = $search_fields->next ) { my $search_field_unblessed = $search_field->unblessed; $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios; + $search_field_unblessed->{aliases} = $search_fields_aliases->{$search_field_unblessed->{name}}; push @all_search_fields, $search_field_unblessed; } 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 bd726dacca..18091c6157 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 @@ -169,13 +169,14 @@ a.add, a.delete { <thead> <tr> <th>Name</th> + <th>Aliases</th> <th>Label</th> <th>Type</th> <th colspan="2">Searchable</th> <th>Weight</th> </tr> <tr> - <th colspan=3> </th> + <th colspan=4> </th> <th>Staff interface</th> <th>OPAC</th> <th> </th> @@ -191,6 +192,9 @@ a.add, a.delete { <input type="text" name="search_field_name" value="[% search_field.name | html %]" /> [% END %] </td> + <td> + [% search_field.aliases.join(',') | html %] + </td> <td> [% IF search_field.mandatory %] <input type="text" name="search_field_label" value="[% search_field.label | html %]" readonly /> -- 2.39.5