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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-15 / +12 lines)
Lines 849-854 sub _modify_string_by_type { Link Here
849
            $str = "[$from TO $until]";
849
            $str = "[$from TO $until]";
850
        }
850
        }
851
    }
851
    }
852
    elsif($type eq 'st-date-normalized'){
853
        if ($str =~ /^(.*) - (.*)$/) {
854
            my $from = $1 || '*';
855
            my $until = $2 || '*';
856
            $str = "[$from TO $until]";
857
        }
858
    }
852
    return $str;
859
    return $str;
853
}
860
}
854
861
Lines 1087-1093 sub _fix_limit_special_cases { Link Here
1087
    my ( $self, $limits ) = @_;
1094
    my ( $self, $limits ) = @_;
1088
1095
1089
    my @new_lim;
1096
    my @new_lim;
1090
    my $ranges;
1091
    foreach my $l (@$limits) {
1097
    foreach my $l (@$limits) {
1092
        # This is set up by opac-search.pl
1098
        # This is set up by opac-search.pl
1093
        if ( $l =~ /^yr,st-numeric,ge[=:]/ ) {
1099
        if ( $l =~ /^yr,st-numeric,ge[=:]/ ) {
Lines 1155-1169 sub _fix_limit_special_cases { Link Here
1155
                push @new_lim, $term;
1161
                push @new_lim, $term;
1156
            }
1162
            }
1157
        }
1163
        }
1158
        elsif ($l =~ /^acqdate,(ge|le),st-date-normalized=/ ) {
1164
        elsif ($l =~ /^acqdate,st-date-normalized=/ ) {
1159
            my ($fromdate) = ( $l =~ /^acqdate,ge,st-date-normalized=(.*)$/ );
1165
            my ($date) = ( $l =~ /^acqdate,st-date-normalized=(.*)$/ );
1160
            my ($todate) = ( $l =~ /^acqdate,le,st-date-normalized=(.*)$/ );
1166
            next unless defined($date);
1161
            $fromdate ||= '*';
1167
            $date = $self->_modify_string_by_type(type => 'st-date-normalized', operand => $date);
1162
            $todate ||= '*';
1168
            push @new_lim, "date-of-acquisition.raw:$date";
1163
            $ranges->{'date-of-acquisition.raw'} = {
1164
                from => $fromdate,
1165
                to => $todate
1166
            }
1167
        }
1169
        }
1168
        else {
1170
        else {
1169
            my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/;
1171
            my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/;
Lines 1176-1186 sub _fix_limit_special_cases { Link Here
1176
            }
1178
            }
1177
        }
1179
        }
1178
1180
1179
        if ( $ranges ) {
1180
            foreach my $index ( keys %$ranges ) {
1181
                push @new_lim, "$index:[$ranges->{$index}{from} TO $ranges->{$index}{to}]"
1182
            }
1183
        }
1184
    }
1181
    }
1185
    return \@new_lim;
1182
    return \@new_lim;
1186
}
1183
}
(-)a/labels/label-item-search.pl (-2 / +1 lines)
Lines 69-76 if ( $op eq "do_search" ) { Link Here
69
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
69
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
70
70
71
    if (!@limits) {
71
    if (!@limits) {
72
        push(@limits, "acqdate,ge,st-date-normalized=$datefrom") if ($datefrom);
72
        push(@limits, "acqdate,st-date-normalized=$datefrom - $dateto");
73
        push(@limits, "acqdate,le,st-date-normalized=$dateto") if ($dateto);
74
    }
73
    }
75
74
76
    my ( $build_error, $query, $simple_query, $query_cgi,
75
    my ( $build_error, $query, $simple_query, $query_cgi,
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-2 / +33 lines)
Lines 219-225 subtest 'build_authorities_query_compat() tests' => sub { Link Here
219
};
219
};
220
220
221
subtest 'build_query tests' => sub {
221
subtest 'build_query tests' => sub {
222
    plan tests => 58;
222
    plan tests => 62;
223
223
224
    my $qb;
224
    my $qb;
225
225
Lines 578-583 subtest 'build_query tests' => sub { Link Here
578
    is( $limit, '(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))', "Limit formed correctly when no search terms");
578
    is( $limit, '(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))', "Limit formed correctly when no search terms");
579
    is( $limit_cgi,'&limit=author%3ADillinger%20Escaplan&limit=mc-itype%2Cphr%3ABOOK&limit=mc-itype%2Cphr%3ACD', "Limit CGI formed correctly when no search terms");
579
    is( $limit_cgi,'&limit=author%3ADillinger%20Escaplan&limit=mc-itype%2Cphr%3ABOOK&limit=mc-itype%2Cphr%3ACD', "Limit CGI formed correctly when no search terms");
580
    is( $limit_desc,'(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))',"Limit desc formed correctly when no search terms");
580
    is( $limit_desc,'(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))',"Limit desc formed correctly when no search terms");
581
582
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
583
        ['acqdate,st-date-normalized= - '] );
584
    is(
585
        $query->{query}{query_string}{query},
586
        '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO *]',
587
        'If no date all date-of-acquisition are selected'
588
    );
589
590
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
591
        ['acqdate,st-date-normalized=2024-08-01 - '] );
592
    is(
593
        $query->{query}{query_string}{query},
594
        '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO *]',
595
        'Open start date in date range of an st-date-normalized search is handled properly'
596
    );
597
598
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
599
        ['acqdate,st-date-normalized= - 2024-08-30'] );
600
    is(
601
        $query->{query}{query_string}{query},
602
        '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO 2024-08-30]',
603
        'Open end date in date range of an st-date-normalized search is handled properly'
604
    );
605
606
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
607
        ['acqdate,st-date-normalized=2024-08-01 - 2024-08-30'] );
608
    is(
609
        $query->{query}{query_string}{query},
610
        '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO 2024-08-30]',
611
        'Date range in an st-date-normalized search is handled properly'
612
    );
581
};
613
};
582
614
583
615
584
- 

Return to bug 30745