@@ -, +, @@ Configuration --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 206 +++++++++++---------- admin/searchengine/elasticsearch/mappings.pl | 10 + .../admin/searchengine/elasticsearch/mappings.tt | 6 +- 3 files changed, 120 insertions(+), 102 deletions(-) --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ a/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, +and it returns something that can be sent to L. + +B: 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) @@ -607,107 +712,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, -and it returns something that can be sent to L. - -B: 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 ) = @_; --- a/admin/searchengine/elasticsearch/mappings.pl +++ a/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; } --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt @@ -169,13 +169,14 @@ a.add, a.delete { Name + Aliases Label Type Searchable Weight -   +   Staff interface OPAC   @@ -192,6 +193,9 @@ a.add, a.delete { [% END %] + [% search_field.aliases.join(',') | html %] + + [% IF search_field.mandatory %] [% ELSE %] --