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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-7 / +5 lines)
Lines 854-863 sub _modify_string_by_type { Link Here
854
            my $until = $2 || '*';
854
            my $until = $2 || '*';
855
            $str = "[$from TO $until]";
855
            $str = "[$from TO $until]";
856
        }
856
        }
857
    }
857
    } elsif ( $type eq 'st-date-normalized' ) {
858
    elsif($type eq 'st-date-normalized'){
858
        if ( $str =~ /^(.*) - (.*)$/ ) {
859
        if ($str =~ /^(.*) - (.*)$/) {
859
            my $from  = $1 || '*';
860
         my $from = $1 || '*';
861
            my $until = $2 || '*';
860
            my $until = $2 || '*';
862
            $str = "[$from TO $until]";
861
            $str = "[$from TO $until]";
863
        }
862
        }
Lines 1171-1181 sub _fix_limit_special_cases { Link Here
1171
            else {
1170
            else {
1172
                push @new_lim, $term;
1171
                push @new_lim, $term;
1173
            }
1172
            }
1174
        }
1173
        } elsif ( $l =~ /^acqdate,st-date-normalized=/ ) {
1175
        elsif ($l =~ /^acqdate,st-date-normalized=/ ) {
1176
            my ($date) = ( $l =~ /^acqdate,st-date-normalized=(.*)$/ );
1174
            my ($date) = ( $l =~ /^acqdate,st-date-normalized=(.*)$/ );
1177
            next unless defined($date);
1175
            next unless defined($date);
1178
            $date = $self->_modify_string_by_type(type => 'st-date-normalized', operand => $date);
1176
            $date = $self->_modify_string_by_type( type => 'st-date-normalized', operand => $date );
1179
            push @new_lim, "date-of-acquisition.raw:$date";
1177
            push @new_lim, "date-of-acquisition.raw:$date";
1180
        }
1178
        }
1181
        else {
1179
        else {
(-)a/labels/label-item-search.pl (-21 / +19 lines)
Lines 40-46 my $query = CGI->new; Link Here
40
my $type      = $query->param('type');
40
my $type      = $query->param('type');
41
my $op        = $query->param('op') || '';
41
my $op        = $query->param('op') || '';
42
my $batch_id  = $query->param('batch_id');
42
my $batch_id  = $query->param('batch_id');
43
my @limits    = split(" AND ", $query->param('limits') || "");
43
my @limits = split( " AND ", $query->param('limits') || "" );
44
my $startfrom = $query->param('startfrom') || 1;
44
my $startfrom = $query->param('startfrom') || 1;
45
my ($template, $loggedinuser, $cookie) = (undef, undef, undef);
45
my ($template, $loggedinuser, $cookie) = (undef, undef, undef);
46
my (
46
my (
Lines 63-95 if ( $op eq "do_search" ) { Link Here
63
    $datefrom = $query->param('datefrom');
63
    $datefrom = $query->param('datefrom');
64
    $dateto   = $query->param('dateto');
64
    $dateto   = $query->param('dateto');
65
65
66
    my $builder = Koha::SearchEngine::QueryBuilder->new(
66
    my $builder  = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
67
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
67
    my $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
68
    my $searcher = Koha::SearchEngine::Search->new(
69
        { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
70
68
71
    if (!@limits) {
69
    if ( !@limits ) {
72
       push(@limits, "acqdate,st-date-normalized=$datefrom - $dateto");
70
        push( @limits, "acqdate,st-date-normalized=$datefrom - $dateto" );
73
    }
71
    }
74
72
75
    my ( $build_error, $query, $simple_query, $query_cgi,
73
    my (
76
        $query_desc, $limit, $limit_cgi, $limit_desc,
74
        $build_error, $query, $simple_query, $query_cgi,
77
        $query_type )
75
        $query_desc,  $limit, $limit_cgi,    $limit_desc,
78
        = $builder->build_query_compat( undef, [$ccl_textbox], [$idx], \@limits);
76
        $query_type
77
    ) = $builder->build_query_compat( undef, [$ccl_textbox], [$idx], \@limits );
79
78
80
    my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
79
    my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
81
80
82
    my ( $error, $results, $facets ) = $searcher->search_compat(
81
    my ( $error, $results, $facets ) = $searcher->search_compat(
83
        $query, $simple_query, [], ['biblioserver'], $resultsperpage, $offset,
82
        $query, $simple_query, [],          ['biblioserver'], $resultsperpage, $offset,
84
        undef, undef, $query_type, undef
83
        undef,  undef,         $query_type, undef
85
    );
84
    );
86
85
87
    if (!defined $error && defined($results) && @{$results->{biblioserver}{RECORDS}} > 0 ) {
86
    if ( !defined $error && defined($results) && @{ $results->{biblioserver}{RECORDS} } > 0 ) {
88
        $show_results = grep { defined $_ } @{$results->{biblioserver}{RECORDS}};
87
        $show_results = grep { defined $_ } @{ $results->{biblioserver}{RECORDS} };
89
        $marcresults = [ grep { defined $_ } @{$results->{biblioserver}{RECORDS}} ];
88
        $marcresults  = [ grep { defined $_ } @{ $results->{biblioserver}{RECORDS} } ];
90
        $total_hits = $results->{biblioserver}{hits};
89
        $total_hits   = $results->{biblioserver}{hits};
91
    }
90
    } else {
92
    else {
93
        Koha::Logger->get->warn("ERROR label-item-search: no results from simple_search_compat");
91
        Koha::Logger->get->warn("ERROR label-item-search: no results from simple_search_compat");
94
92
95
        # leave $show_results undef
93
        # leave $show_results undef
Lines 192-204 if ($show_results) { Link Here
192
    );
190
    );
193
191
194
    $template->param(
192
    $template->param(
195
        results     => ($show_results ? 1 : 0),
193
        results     => ( $show_results ? 1 : 0 ),
196
        result_set  => \@results_set,
194
        result_set  => \@results_set,
197
        batch_id    => $batch_id,
195
        batch_id    => $batch_id,
198
        type        => $type,
196
        type        => $type,
199
        idx         => $idx,
197
        idx         => $idx,
200
        ccl_textbox => $ccl_textbox,
198
        ccl_textbox => $ccl_textbox,
201
        limits      => join(" AND ", @limits),
199
        limits      => join( " AND ", @limits ),
202
    );
200
    );
203
}
201
}
204
202
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-11 / +18 lines)
Lines 671-704 subtest 'build_query tests' => sub { Link Here
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
673
674
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
674
    ( undef, $query ) = $qb->build_query_compat(
675
        ['acqdate,st-date-normalized= - '] );
675
        undef, ['barcode123123'], ['bc'],
676
        ['acqdate,st-date-normalized= - ']
677
    );
676
    is(
678
    is(
677
        $query->{query}{query_string}{query},
679
        $query->{query}{query_string}{query},
678
        '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO *]',
680
        '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO *]',
679
        'If no date all date-of-acquisition are selected'
681
        'If no date all date-of-acquisition are selected'
680
    );
682
    );
681
683
682
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
684
    ( undef, $query ) = $qb->build_query_compat(
683
        ['acqdate,st-date-normalized=2024-08-01 - '] );
685
        undef, ['barcode123123'], ['bc'],
686
        ['acqdate,st-date-normalized=2024-08-01 - ']
687
    );
684
    is(
688
    is(
685
        $query->{query}{query_string}{query},
689
        $query->{query}{query_string}{query},
686
        '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO *]',
690
        '(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'
691
        'Open start date in date range of an st-date-normalized search is handled properly'
688
    );
692
    );
689
693
690
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
694
    ( undef, $query ) = $qb->build_query_compat(
691
        ['acqdate,st-date-normalized= - 2024-08-30'] );
695
        undef, ['barcode123123'], ['bc'],
696
        ['acqdate,st-date-normalized= - 2024-08-30']
697
    );
692
    is(
698
    is(
693
        $query->{query}{query_string}{query},
699
        $query->{query}{query_string}{query},
694
        '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO 2024-08-30]',
700
        '(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'
701
        'Open end date in date range of an st-date-normalized search is handled properly'
696
    );
702
    );
697
703
698
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'],
704
    ( undef, $query ) = $qb->build_query_compat(
699
        ['acqdate,st-date-normalized=2024-08-01 - 2024-08-30'] );
705
        undef, ['barcode123123'], ['bc'],
700
   is(
706
        ['acqdate,st-date-normalized=2024-08-01 - 2024-08-30']
701
       $query->{query}{query_string}{query},
707
    );
708
    is(
709
        $query->{query}{query_string}{query},
702
        '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO 2024-08-30]',
710
        '(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'
711
        'Date range in an st-date-normalized search is handled properly'
704
    );
712
    );
705
- 

Return to bug 30745