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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-2 / +10 lines)
Lines 608-614 sub _convert_index_fields { Link Here
608
    my ( $self, @indexes ) = @_;
608
    my ( $self, @indexes ) = @_;
609
609
610
    my %index_type_convert =
610
    my %index_type_convert =
611
      ( __default => undef, phr => 'phrase', rtrn => 'right-truncate' );
611
      ( __default => undef, phr => 'phrase', rtrn => 'right-truncate', 'st-year' => 'st-year' );
612
612
613
    # Convert according to our table, drop anything that doesn't convert.
613
    # Convert according to our table, drop anything that doesn't convert.
614
    # If a field starts with mc- we save it as it's used (and removed) later
614
    # If a field starts with mc- we save it as it's used (and removed) later
Lines 715-720 sub _modify_string_by_type { Link Here
715
715
716
    $str .= '*' if $type eq 'right-truncate';
716
    $str .= '*' if $type eq 'right-truncate';
717
    $str = '"' . $str . '"' if $type eq 'phrase';
717
    $str = '"' . $str . '"' if $type eq 'phrase';
718
    if ($type eq 'st-year') {
719
        my ($from, $until);
720
        if ($str =~ /^(.*)-(.*)$/) {
721
            $from = $1 || '*';
722
            $until = $2 || '*';
723
            $str = "[$from TO $until]";
724
        }
725
    }
718
    return $str;
726
    return $str;
719
}
727
}
720
728
Lines 787-793 sub _create_query_string { Link Here
787
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
795
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
788
796
789
        my $oand = $self->_modify_string_by_type(%$_);
797
        my $oand = $self->_modify_string_by_type(%$_);
790
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1;
798
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1 && $_->{type} ne 'st-year';
791
        "$otor($field$oand)";
799
        "$otor($field$oand)";
792
    } @queries;
800
    } @queries;
793
}
801
}
(-)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 => 30;
172
    plan tests => 34;
173
173
174
    my $qb;
174
    my $qb;
175
175
Lines 238-243 subtest 'build_query tests' => sub { Link Here
238
        'multiple query terms are enclosed in parenthesis while a single one is not'
238
        'multiple query terms are enclosed in parenthesis while a single one is not'
239
    );
239
    );
240
240
241
    ( undef, $query ) = $qb->build_query_compat( undef, ['2019'], ['yr,st-year'] );
242
    is(
243
        $query->{query}{query_string}{query},
244
        '(date-of-publication:2019)',
245
        'Year in an st-year search is handled properly'
246
    );
247
248
    ( undef, $query ) = $qb->build_query_compat( undef, ['2018-2019'], ['yr,st-year'] );
249
    is(
250
        $query->{query}{query_string}{query},
251
        '(date-of-publication:[2018 TO 2019])',
252
        'Year range in an st-year search is handled properly'
253
    );
254
255
    ( undef, $query ) = $qb->build_query_compat( undef, ['-2019'], ['yr,st-year'] );
256
    is(
257
        $query->{query}{query_string}{query},
258
        '(date-of-publication:[* TO 2019])',
259
        'Open start year in year range of an st-year search is handled properly'
260
    );
261
262
    ( undef, $query ) = $qb->build_query_compat( undef, ['2019-'], ['yr,st-year'] );
263
    is(
264
        $query->{query}{query_string}{query},
265
        '(date-of-publication:[2019 TO *])',
266
        'Open end year in year range of an st-year search is handled properly'
267
    );
268
269
    # Enable auto-truncation
241
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
270
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
242
271
243
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
272
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
244
- 

Return to bug 22524