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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-2 / +10 lines)
Lines 622-628 sub _convert_index_fields { Link Here
622
    my ( $self, @indexes ) = @_;
622
    my ( $self, @indexes ) = @_;
623
623
624
    my %index_type_convert =
624
    my %index_type_convert =
625
      ( __default => undef, phr => 'phrase', rtrn => 'right-truncate' );
625
      ( __default => undef, phr => 'phrase', rtrn => 'right-truncate', 'st-year' => 'st-year' );
626
626
627
    # Convert according to our table, drop anything that doesn't convert.
627
    # Convert according to our table, drop anything that doesn't convert.
628
    # If a field starts with mc- we save it as it's used (and removed) later
628
    # If a field starts with mc- we save it as it's used (and removed) later
Lines 729-734 sub _modify_string_by_type { Link Here
729
729
730
    $str .= '*' if $type eq 'right-truncate';
730
    $str .= '*' if $type eq 'right-truncate';
731
    $str = '"' . $str . '"' if $type eq 'phrase';
731
    $str = '"' . $str . '"' if $type eq 'phrase';
732
    if ($type eq 'st-year') {
733
        my ($from, $until);
734
        if ($str =~ /^(.*)-(.*)$/) {
735
            $from = $1 || '*';
736
            $until = $2 || '*';
737
            $str = "[$from TO $until]";
738
        }
739
    }
732
    return $str;
740
    return $str;
733
}
741
}
734
742
Lines 801-807 sub _create_query_string { Link Here
801
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
809
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
802
810
803
        my $oand = $self->_modify_string_by_type(%$_);
811
        my $oand = $self->_modify_string_by_type(%$_);
804
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1;
812
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1 && $_->{type} ne 'st-year';
805
        "$otor($field$oand)";
813
        "$otor($field$oand)";
806
    } @queries;
814
    } @queries;
807
}
815
}
(-)a/admin/searchengine/elasticsearch/mappings.yaml (-2 / +2 lines)
Lines 3167-3174 biblios: Link Here
3167
        sort: ~
3167
        sort: ~
3168
        suggestible: ''
3168
        suggestible: ''
3169
    type: ''
3169
    type: ''
3170
  pubdate:
3170
  date-of-publication:
3171
    label: pubdate
3171
    label: date-of-publication
3172
    mappings:
3172
    mappings:
3173
      - facet: ''
3173
      - facet: ''
3174
        marc_field: 008_/7-10
3174
        marc_field: 008_/7-10
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-2 / +30 lines)
Lines 169-175 subtest 'build_authorities_query_compat() tests' => sub { Link Here
169
};
169
};
170
170
171
subtest 'build_query tests' => sub {
171
subtest 'build_query tests' => sub {
172
    plan tests => 33;
172
    plan tests => 37;
173
173
174
    my $qb;
174
    my $qb;
175
175
Lines 243-248 subtest 'build_query tests' => sub { Link Here
243
    is($query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query');
243
    is($query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query');
244
    is($query_desc, '(title:("donald duck")) (author:(walt disney))', 'query desc ok for multiterm query');
244
    is($query_desc, '(title:("donald duck")) (author:(walt disney))', 'query desc ok for multiterm query');
245
245
246
    ( undef, $query ) = $qb->build_query_compat( undef, ['2019'], ['yr,st-year'] );
247
    is(
248
        $query->{query}{query_string}{query},
249
        '(date-of-publication:2019)',
250
        'Year in an st-year search is handled properly'
251
    );
252
253
    ( undef, $query ) = $qb->build_query_compat( undef, ['2018-2019'], ['yr,st-year'] );
254
    is(
255
        $query->{query}{query_string}{query},
256
        '(date-of-publication:[2018 TO 2019])',
257
        'Year range in an st-year search is handled properly'
258
    );
259
260
    ( undef, $query ) = $qb->build_query_compat( undef, ['-2019'], ['yr,st-year'] );
261
    is(
262
        $query->{query}{query_string}{query},
263
        '(date-of-publication:[* TO 2019])',
264
        'Open start year in year range of an st-year search is handled properly'
265
    );
266
267
    ( undef, $query ) = $qb->build_query_compat( undef, ['2019-'], ['yr,st-year'] );
268
    is(
269
        $query->{query}{query_string}{query},
270
        '(date-of-publication:[2019 TO *])',
271
        'Open end year in year range of an st-year search is handled properly'
272
    );
273
274
    # Enable auto-truncation
246
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
275
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
247
276
248
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
277
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
249
- 

Return to bug 22524