View | Details | Raw Unified | Return to bug 25054
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-101 / +105 lines)
Lines 50-55 use C4::Context; Link Here
50
use Koha::Exceptions;
50
use Koha::Exceptions;
51
use Koha::Caches;
51
use Koha::Caches;
52
52
53
our %index_field_convert = (
54
    'kw' => '',
55
    'ab' => 'abstract',
56
    'au' => 'author',
57
    'lcn' => 'local-classification',
58
    'callnum' => 'local-classification',
59
    'record-type' => 'rtype',
60
    'mc-rtype' => 'rtype',
61
    'mus' => 'rtype',
62
    'lc-card' => 'lc-card-number',
63
    'sn' => 'local-number',
64
    'biblionumber' => 'local-number',
65
    'yr' => 'date-of-publication',
66
    'pubdate' => 'date-of-publication',
67
    'acqdate' => 'date-of-acquisition',
68
    'date/time-last-modified' => 'date-time-last-modified',
69
    'dtlm' => 'date-time-last-modified',
70
    'diss' => 'dissertation-information',
71
    'nb' => 'isbn',
72
    'ns' => 'issn',
73
    'music-number' => 'identifier-publisher-for-music',
74
    'number-music-publisher' => 'identifier-publisher-for-music',
75
    'music' => 'identifier-publisher-for-music',
76
    'ident' => 'identifier-standard',
77
    'cpn' => 'corporate-name',
78
    'cfn' => 'conference-name',
79
    'pn' => 'personal-name',
80
    'pb' => 'publisher',
81
    'pv' => 'provider',
82
    'nt' => 'note',
83
    'notes' => 'note',
84
    'rcn' => 'record-control-number',
85
    'su' => 'subject',
86
    'su-to' => 'subject',
87
    #'su-geo' => 'subject',
88
    'su-ut' => 'subject',
89
    'ti' => 'title',
90
    'se' => 'title-series',
91
    'ut' => 'title-uniform',
92
    'an' => 'koha-auth-number',
93
    'authority-number' => 'koha-auth-number',
94
    'at' => 'authtype',
95
    'he' => 'heading',
96
    'rank' => 'relevance',
97
    'phr' => 'st-phrase',
98
    'wrdl' => 'st-word-list',
99
    'rt' => 'right-truncation',
100
    'rtrn' => 'right-truncation',
101
    'ltrn' => 'left-truncation',
102
    'rltrn' => 'left-and-right',
103
    'mc-itemtype' => 'itemtype',
104
    'mc-ccode' => 'ccode',
105
    'branch' => 'homebranch',
106
    'mc-loc' => 'location',
107
    'loc' => 'location',
108
    'stocknumber' => 'number-local-acquisition',
109
    'inv' => 'number-local-acquisition',
110
    'bc' => 'barcode',
111
    'mc-itype' => 'itype',
112
    'aub' => 'author-personal-bibliography',
113
    'auo' => 'author-in-order',
114
    'ff8-22' => 'ta',
115
    'aud' => 'ta',
116
    'audience' => 'ta',
117
    'frequency-code' => 'ff8-18',
118
    'illustration-code' => 'ff8-18-21',
119
    'regularity-code' => 'ff8-19',
120
    'type-of-serial' => 'ff8-21',
121
    'format' => 'ff8-23',
122
    'conference-code' => 'ff8-29',
123
    'festschrift-indicator' => 'ff8-30',
124
    'index-indicator' => 'ff8-31',
125
    'fiction' => 'lf',
126
    'fic' => 'lf',
127
    'literature-code' => 'lf',
128
    'biography' => 'bio',
129
    'ff8-34' => 'bio',
130
    'biography-code' => 'bio',
131
    'l-format' => 'ff7-01-02',
132
    'lex' => 'lexile-number',
133
    'hi' => 'host-item-number',
134
    'itu' => 'index-term-uncontrolled',
135
    'itg' => 'index-term-genre',
136
);
137
my $field_name_pattern = '[\w\-]+';
138
my $multi_field_pattern = "(?:\\.$field_name_pattern)*";
139
140
=head2 get_index_field_convert
141
142
    my @index_params = Koha::SearchEngine::Elasticsearch::QueryBuilder->get_index_field_convert();
143
144
Converts zebra-style search index notation into elasticsearch-style.
145
146
C<@indexes> is an array of index names, as presented to L<build_query_compat>,
147
and it returns something that can be sent to L<build_query>.
148
149
B<TODO>: this will pull from the elasticsearch mappings table to figure out
150
types.
151
152
=cut
153
154
sub get_index_field_convert() {
155
    return \%index_field_convert;
156
}
157
53
=head2 build_query
158
=head2 build_query
54
159
55
    my $simple_query = $builder->build_query("hello", %options)
160
    my $simple_query = $builder->build_query("hello", %options)
Lines 607-713 sub _convert_sort_fields { Link Here
607
    } @sort_by;
712
    } @sort_by;
608
}
713
}
609
714
610
=head2 _convert_index_fields
611
612
    my @index_params = $self->_convert_index_fields(@indexes);
613
614
Converts zebra-style search index notation into elasticsearch-style.
615
616
C<@indexes> is an array of index names, as presented to L<build_query_compat>,
617
and it returns something that can be sent to L<build_query>.
618
619
B<TODO>: this will pull from the elasticsearch mappings table to figure out
620
types.
621
622
=cut
623
624
our %index_field_convert = (
625
    'kw' => '',
626
    'ab' => 'abstract',
627
    'au' => 'author',
628
    'lcn' => 'local-classification',
629
    'callnum' => 'local-classification',
630
    'record-type' => 'rtype',
631
    'mc-rtype' => 'rtype',
632
    'mus' => 'rtype',
633
    'lc-card' => 'lc-card-number',
634
    'sn' => 'local-number',
635
    'biblionumber' => 'local-number',
636
    'yr' => 'date-of-publication',
637
    'pubdate' => 'date-of-publication',
638
    'acqdate' => 'date-of-acquisition',
639
    'date/time-last-modified' => 'date-time-last-modified',
640
    'dtlm' => 'date-time-last-modified',
641
    'diss' => 'dissertation-information',
642
    'nb' => 'isbn',
643
    'ns' => 'issn',
644
    'music-number' => 'identifier-publisher-for-music',
645
    'number-music-publisher' => 'identifier-publisher-for-music',
646
    'music' => 'identifier-publisher-for-music',
647
    'ident' => 'identifier-standard',
648
    'cpn' => 'corporate-name',
649
    'cfn' => 'conference-name',
650
    'pn' => 'personal-name',
651
    'pb' => 'publisher',
652
    'pv' => 'provider',
653
    'nt' => 'note',
654
    'notes' => 'note',
655
    'rcn' => 'record-control-number',
656
    'su' => 'subject',
657
    'su-to' => 'subject',
658
    #'su-geo' => 'subject',
659
    'su-ut' => 'subject',
660
    'ti' => 'title',
661
    'se' => 'title-series',
662
    'ut' => 'title-uniform',
663
    'an' => 'koha-auth-number',
664
    'authority-number' => 'koha-auth-number',
665
    'at' => 'authtype',
666
    'he' => 'heading',
667
    'rank' => 'relevance',
668
    'phr' => 'st-phrase',
669
    'wrdl' => 'st-word-list',
670
    'rt' => 'right-truncation',
671
    'rtrn' => 'right-truncation',
672
    'ltrn' => 'left-truncation',
673
    'rltrn' => 'left-and-right',
674
    'mc-itemtype' => 'itemtype',
675
    'mc-ccode' => 'ccode',
676
    'branch' => 'homebranch',
677
    'mc-loc' => 'location',
678
    'loc' => 'location',
679
    'stocknumber' => 'number-local-acquisition',
680
    'inv' => 'number-local-acquisition',
681
    'bc' => 'barcode',
682
    'mc-itype' => 'itype',
683
    'aub' => 'author-personal-bibliography',
684
    'auo' => 'author-in-order',
685
    'ff8-22' => 'ta',
686
    'aud' => 'ta',
687
    'audience' => 'ta',
688
    'frequency-code' => 'ff8-18',
689
    'illustration-code' => 'ff8-18-21',
690
    'regularity-code' => 'ff8-19',
691
    'type-of-serial' => 'ff8-21',
692
    'format' => 'ff8-23',
693
    'conference-code' => 'ff8-29',
694
    'festschrift-indicator' => 'ff8-30',
695
    'index-indicator' => 'ff8-31',
696
    'fiction' => 'lf',
697
    'fic' => 'lf',
698
    'literature-code' => 'lf',
699
    'biography' => 'bio',
700
    'ff8-34' => 'bio',
701
    'biography-code' => 'bio',
702
    'l-format' => 'ff7-01-02',
703
    'lex' => 'lexile-number',
704
    'hi' => 'host-item-number',
705
    'itu' => 'index-term-uncontrolled',
706
    'itg' => 'index-term-genre',
707
);
708
my $field_name_pattern = '[\w\-]+';
709
my $multi_field_pattern = "(?:\\.$field_name_pattern)*";
710
711
sub _convert_index_fields {
715
sub _convert_index_fields {
712
    my ( $self, @indexes ) = @_;
716
    my ( $self, @indexes ) = @_;
713
717
(-)a/admin/searchengine/elasticsearch/mappings.pl (+10 lines)
Lines 24-29 use C4::Output; Link Here
24
use C4::Auth;
24
use C4::Auth;
25
25
26
use Koha::SearchEngine::Elasticsearch;
26
use Koha::SearchEngine::Elasticsearch;
27
use Koha::SearchEngine::Elasticsearch::QueryBuilder;
27
use Koha::SearchMarcMaps;
28
use Koha::SearchMarcMaps;
28
use Koha::SearchFields;
29
use Koha::SearchFields;
29
use Koha::Caches;
30
use Koha::Caches;
Lines 77-82 my $update_mappings = sub { Link Here
77
    }
78
    }
78
};
79
};
79
80
81
my $search_fields_aliases = {};
82
while ( my ( $key, $value ) = each(%{Koha::SearchEngine::Elasticsearch::QueryBuilder->get_index_field_convert}) ) {
83
    my $field_aliases = $search_fields_aliases->{$value};
84
    $field_aliases = [] unless $field_aliases;
85
    push @$field_aliases, $key;
86
    $search_fields_aliases->{$value} = $field_aliases;
87
}
88
80
if ( $op eq 'edit' ) {
89
if ( $op eq 'edit' ) {
81
90
82
    $schema->storage->txn_begin;
91
    $schema->storage->txn_begin;
Lines 260-265 my @all_search_fields; Link Here
260
while ( my $search_field = $search_fields->next ) {
269
while ( my $search_field = $search_fields->next ) {
261
    my $search_field_unblessed = $search_field->unblessed;
270
    my $search_field_unblessed = $search_field->unblessed;
262
    $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios;
271
    $search_field_unblessed->{mapped_biblios} = 1 if $search_field->is_mapped_biblios;
272
    $search_field_unblessed->{aliases} = $search_fields_aliases->{$search_field_unblessed->{name}};
263
    push @all_search_fields, $search_field_unblessed;
273
    push @all_search_fields, $search_field_unblessed;
264
}
274
}
265
275
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt (-2 / +5 lines)
Lines 169-181 a.add, a.delete { Link Here
169
                <thead>
169
                <thead>
170
                  <tr>
170
                  <tr>
171
                    <th>Name</th>
171
                    <th>Name</th>
172
                    <th>Aliases</th>
172
                    <th>Label</th>
173
                    <th>Label</th>
173
                    <th>Type</th>
174
                    <th>Type</th>
174
                    <th colspan="2">Searchable</th>
175
                    <th colspan="2">Searchable</th>
175
                    <th>Weight</th>
176
                    <th>Weight</th>
176
                  </tr>
177
                  </tr>
177
                  <tr>
178
                  <tr>
178
                    <th colspan=3>&nbsp;</th>
179
                    <th colspan=4>&nbsp;</th>
179
                    <th>Staff interface</th>
180
                    <th>Staff interface</th>
180
                    <th>OPAC</th>
181
                    <th>OPAC</th>
181
                    <th>&nbsp;</th>
182
                    <th>&nbsp;</th>
Lines 191-196 a.add, a.delete { Link Here
191
                            <input type="text" name="search_field_name" value="[% search_field.name | html %]" />
192
                            <input type="text" name="search_field_name" value="[% search_field.name | html %]" />
192
                        [% END %]
193
                        [% END %]
193
                      </td>
194
                      </td>
195
                      <td>
196
                          [% search_field.aliases.join(',') | html %]
197
                      </td>
194
                      <td>
198
                      <td>
195
                        [% IF search_field.mandatory %]
199
                        [% IF search_field.mandatory %]
196
                            <input type="text" name="search_field_label" value="[% search_field.label | html %]" readonly />
200
                            <input type="text" name="search_field_label" value="[% search_field.label | html %]" readonly />
197
- 

Return to bug 25054