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
        if ($str =~ /^(.*)-(.*)$/) {
734
            my $from = $1 || '*';
735
            my $until = $2 || '*';
736
            $str = "[$from TO $until]";
737
        }
738
    }
732
    return $str;
739
    return $str;
733
}
740
}
734
741
Lines 801-807 sub _create_query_string { Link Here
801
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
808
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
802
809
803
        my $oand = $self->_modify_string_by_type(%$_);
810
        my $oand = $self->_modify_string_by_type(%$_);
804
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1;
811
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1 && (!defined $_->{type} || $_->{type} ne 'st-year');
805
        "$otor($field$oand)";
812
        "$otor($field$oand)";
806
    } @queries;
813
    } @queries;
807
}
814
}
Lines 869-874 sub _fix_limit_special_cases { Link Here
869
        elsif ( $l =~ /^yr,st-numeric=/ ) {
876
        elsif ( $l =~ /^yr,st-numeric=/ ) {
870
            my ($date) = ( $l =~ /^yr,st-numeric=(.*)$/ );
877
            my ($date) = ( $l =~ /^yr,st-numeric=(.*)$/ );
871
            next unless defined($date);
878
            next unless defined($date);
879
            $date = $self->_modify_string_by_type(type => 'st-year', operand => $date);
872
            push @new_lim, "copydate:$date";
880
            push @new_lim, "copydate:$date";
873
        }
881
        }
874
        elsif ( $l =~ /^available$/ ) {
882
        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 => 33;
172
    plan tests => 38;
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
    ( undef, $query ) = $qb->build_query_compat( undef, ['2019-'], ['yr,st-year'], ['yr,st-numeric=-2019'] );
275
    is(
276
        $query->{query}{query_string}{query},
277
        '(date-of-publication:[2019 TO *]) AND copydate:[* TO 2019]',
278
        'Open end year in year range of an st-year search is handled properly'
279
    );
280
281
    # Enable auto-truncation
246
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
282
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
247
283
248
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
284
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
249
- 

Return to bug 22524