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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-2 / +10 lines)
Lines 620-626 sub _convert_index_fields { Link Here
620
    my ( $self, @indexes ) = @_;
620
    my ( $self, @indexes ) = @_;
621
621
622
    my %index_type_convert =
622
    my %index_type_convert =
623
      ( __default => undef, phr => 'phrase', rtrn => 'right-truncate' );
623
      ( __default => undef, phr => 'phrase', rtrn => 'right-truncate', 'st-year' => 'st-year' );
624
624
625
    # Convert according to our table, drop anything that doesn't convert.
625
    # Convert according to our table, drop anything that doesn't convert.
626
    # If a field starts with mc- we save it as it's used (and removed) later
626
    # If a field starts with mc- we save it as it's used (and removed) later
Lines 727-732 sub _modify_string_by_type { Link Here
727
727
728
    $str .= '*' if $type eq 'right-truncate';
728
    $str .= '*' if $type eq 'right-truncate';
729
    $str = '"' . $str . '"' if $type eq 'phrase';
729
    $str = '"' . $str . '"' if $type eq 'phrase';
730
    if ($type eq 'st-year') {
731
        if ($str =~ /^(.*)-(.*)$/) {
732
            my $from = $1 || '*';
733
            my $until = $2 || '*';
734
            $str = "[$from TO $until]";
735
        }
736
    }
730
    return $str;
737
    return $str;
731
}
738
}
732
739
Lines 799-805 sub _create_query_string { Link Here
799
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
806
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
800
807
801
        my $oand = $self->_modify_string_by_type(%$_);
808
        my $oand = $self->_modify_string_by_type(%$_);
802
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1;
809
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1 && (!defined $_->{type} || $_->{type} ne 'st-year');
803
        "$otor($field$oand)";
810
        "$otor($field$oand)";
804
    } @queries;
811
    } @queries;
805
}
812
}
Lines 867-872 sub _fix_limit_special_cases { Link Here
867
        elsif ( $l =~ /^yr,st-numeric=/ ) {
874
        elsif ( $l =~ /^yr,st-numeric=/ ) {
868
            my ($date) = ( $l =~ /^yr,st-numeric=(.*)$/ );
875
            my ($date) = ( $l =~ /^yr,st-numeric=(.*)$/ );
869
            next unless defined($date);
876
            next unless defined($date);
877
            $date = $self->_modify_string_by_type(type => 'st-year', operand => $date);
870
            push @new_lim, "copydate:$date";
878
            push @new_lim, "copydate:$date";
871
        }
879
        }
872
        elsif ( $l =~ /^available$/ ) {
880
        elsif ( $l =~ /^available$/ ) {
(-)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 / +37 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 => 35;
172
    plan tests => 40;
173
173
174
    my $qb;
174
    my $qb;
175
175
Lines 248-253 subtest 'build_query tests' => sub { Link Here
248
    is($query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query');
248
    is($query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query');
249
    is($query_desc, '(title:("donald duck")) (author:(walt disney))', 'query desc ok for multiterm query');
249
    is($query_desc, '(title:("donald duck")) (author:(walt disney))', 'query desc ok for multiterm query');
250
250
251
    ( undef, $query ) = $qb->build_query_compat( undef, ['2019'], ['yr,st-year'] );
252
    is(
253
        $query->{query}{query_string}{query},
254
        '(date-of-publication:2019)',
255
        'Year in an st-year search is handled properly'
256
    );
257
258
    ( undef, $query ) = $qb->build_query_compat( undef, ['2018-2019'], ['yr,st-year'] );
259
    is(
260
        $query->{query}{query_string}{query},
261
        '(date-of-publication:[2018 TO 2019])',
262
        'Year range in an st-year search is handled properly'
263
    );
264
265
    ( undef, $query ) = $qb->build_query_compat( undef, ['-2019'], ['yr,st-year'] );
266
    is(
267
        $query->{query}{query_string}{query},
268
        '(date-of-publication:[* TO 2019])',
269
        'Open start year in year range of an st-year search is handled properly'
270
    );
271
272
    ( undef, $query ) = $qb->build_query_compat( undef, ['2019-'], ['yr,st-year'] );
273
    is(
274
        $query->{query}{query_string}{query},
275
        '(date-of-publication:[2019 TO *])',
276
        'Open end year in year range of an st-year search is handled properly'
277
    );
278
279
    ( undef, $query ) = $qb->build_query_compat( undef, ['2019-'], ['yr,st-year'], ['yr,st-numeric=-2019'] );
280
    is(
281
        $query->{query}{query_string}{query},
282
        '(date-of-publication:[2019 TO *]) AND copydate:[* TO 2019]',
283
        'Open end year in year range of an st-year search is handled properly'
284
    );
285
286
    # Enable auto-truncation
251
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
287
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
252
288
253
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
289
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
254
- 

Return to bug 22524