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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-16 / +12 lines)
Lines 854-859 sub _modify_string_by_type { Link Here
854
            $str = "[$from TO $until]";
854
            $str = "[$from TO $until]";
855
        }
855
        }
856
    }
856
    }
857
    elsif($type eq 'st-date-normalized'){
858
        if ($str =~ /^(.*) - (.*)$/) {
859
         my $from = $1 || '*';
860
            my $until = $2 || '*';
861
            $str = "[$from TO $until]";	
862
        }
863
    }
857
    return $str;
864
    return $str;
858
}
865
}
859
866
Lines 1097-1103 sub _fix_limit_special_cases { Link Here
1097
    my ( $self, $limits ) = @_;
1104
    my ( $self, $limits ) = @_;
1098
1105
1099
    my @new_lim;
1106
    my @new_lim;
1100
    my $ranges;
1101
    foreach my $l (@$limits) {
1107
    foreach my $l (@$limits) {
1102
        # This is set up by opac-search.pl
1108
        # This is set up by opac-search.pl
1103
        if ( $l =~ /^yr,st-numeric,ge[=:]/ ) {
1109
        if ( $l =~ /^yr,st-numeric,ge[=:]/ ) {
Lines 1165-1179 sub _fix_limit_special_cases { Link Here
1165
                push @new_lim, $term;
1171
                push @new_lim, $term;
1166
            }
1172
            }
1167
        }
1173
        }
1168
        elsif ($l =~ /^acqdate,(ge|le),st-date-normalized=/ ) {
1174
        elsif ($l =~ /^acqdate,st-date-normalized=/ ) {
1169
            my ($fromdate) = ( $l =~ /^acqdate,ge,st-date-normalized=(.*)$/ );
1175
            my ($date) = ( $l =~ /^acqdate,st-date-normalized=(.*)$/ );
1170
            my ($todate) = ( $l =~ /^acqdate,le,st-date-normalized=(.*)$/ );
1176
            next unless defined($date);
1171
            $fromdate ||= '*';
1177
            $date = $self->_modify_string_by_type(type => 'st-date-normalized', operand => $date);
1172
            $todate ||= '*';
1178
            push @new_lim, "date-of-acquisition.raw:$date";
1173
            $ranges->{'date-of-acquisition.raw'} = {
1174
                from => $fromdate,
1175
                to => $todate
1176
            }
1177
        }
1179
        }
1178
        else {
1180
        else {
1179
            my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/;
1181
            my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/;
Lines 1185-1196 sub _fix_limit_special_cases { Link Here
1185
                push @new_lim, $l;
1187
                push @new_lim, $l;
1186
            }
1188
            }
1187
        }
1189
        }
1188
1189
        if ( $ranges ) {
1190
            foreach my $index ( keys %$ranges ) {
1191
                push @new_lim, "$index:[$ranges->{$index}{from} TO $ranges->{$index}{to}]"
1192
            }
1193
        }
1194
    }
1190
    }
1195
    return \@new_lim;
1191
    return \@new_lim;
1196
}
1192
}
(-)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 => 61;
222
    plan tests => 65;
223
223
224
    my $qb;
224
    my $qb;
225
225
Lines 670-675 subtest 'build_query tests' => sub { Link Here
670
    is( $limit, '(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))', "Limit formed correctly when no search terms");
670
    is( $limit, '(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))', "Limit formed correctly when no search terms");
671
    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");
671
    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");
672
    is( $limit_desc,'(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))',"Limit desc formed correctly when no search terms");
672
    is( $limit_desc,'(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))',"Limit desc formed correctly when no search terms");
673
674
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
675
        ['acqdate,st-date-normalized= - '] );
676
    is(
677
        $query->{query}{query_string}{query},
678
        '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO *]',
679
        'If no date all date-of-acquisition are selected'
680
    );
681
682
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
683
        ['acqdate,st-date-normalized=2024-08-01 - '] );
684
    is(
685
        $query->{query}{query_string}{query},
686
        '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO *]',
687
        'Open start date in date range of an st-date-normalized search is handled properly'
688
    );
689
690
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
691
        ['acqdate,st-date-normalized= - 2024-08-30'] );
692
    is(
693
        $query->{query}{query_string}{query},
694
        '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO 2024-08-30]',
695
        'Open end date in date range of an st-date-normalized search is handled properly'
696
    );
697
698
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
699
        ['acqdate,st-date-normalized=2024-08-01 - 2024-08-30'] );
700
   is(
701
       $query->{query}{query_string}{query},
702
        '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO 2024-08-30]',
703
        'Date range in an st-date-normalized search is handled properly'
704
    );
673
};
705
};
674
706
675
707
676
- 

Return to bug 30745