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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-4 / +5 lines)
Lines 1080-1095 sub _fix_limit_special_cases { Link Here
1080
            }
1080
            }
1081
1081
1082
            if (@branchcodes) {
1082
            if (@branchcodes) {
1083
                # We quote the branchcodes here to prevent issues when codes are reserved words in ES, e.g. OR, AND, NOT, etc.
1083
                if ( $branchfield eq "homebranch" ) {
1084
                if ( $branchfield eq "homebranch" ) {
1084
                    push @new_lim, sprintf "(%s)", join " OR ", map { 'homebranch: ' . $_ } @branchcodes;
1085
                    push @new_lim, sprintf "(%s)", join " OR ", map { 'homebranch: "' . $_ . '"' } @branchcodes;
1085
                }
1086
                }
1086
                elsif ( $branchfield eq "holdingbranch" ) {
1087
                elsif ( $branchfield eq "holdingbranch" ) {
1087
                    push @new_lim, sprintf "(%s)", join " OR ", map { 'holdingbranch: ' . $_ } @branchcodes;
1088
                    push @new_lim, sprintf "(%s)", join " OR ", map { 'holdingbranch: "' . $_ . '"' } @branchcodes;
1088
                }
1089
                }
1089
                else {
1090
                else {
1090
                    push @new_lim, sprintf "(%s OR %s)",
1091
                    push @new_lim, sprintf "(%s OR %s)",
1091
                      join( " OR ", map { 'homebranch: ' . $_ } @branchcodes ),
1092
                      join( " OR ", map { 'homebranch: "' . $_ . '"' } @branchcodes ),
1092
                      join( " OR ", map { 'holdingbranch: ' . $_ } @branchcodes );
1093
                      join( " OR ", map { 'holdingbranch: "' . $_ . '"' } @branchcodes );
1093
                }
1094
                }
1094
            }
1095
            }
1095
        }
1096
        }
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-14 / +13 lines)
Lines 725-761 subtest 'build_query_compat() SearchLimitLibrary tests' => sub { Link Here
725
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'both');
725
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'both');
726
    my ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
726
    my ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
727
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
727
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
728
    is( $limit, "(homebranch: CPL OR holdingbranch: CPL)", "Branch limit expanded to home/holding branch");
728
    is( $limit, '(homebranch: "CPL" OR holdingbranch: "CPL")', "Branch limit expanded to home/holding branch");
729
    is( $limit_desc, "(homebranch: CPL OR holdingbranch: CPL)", "Limit description correctly expanded");
729
    is( $limit_desc, '(homebranch: "CPL" OR holdingbranch: "CPL")', "Limit description correctly expanded");
730
    is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded");
730
    is( $limit_cgi, '&limit=branch%3ACPL', "Limit cgi does not get expanded");
731
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
731
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
732
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
732
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
733
    is( $limit, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1] OR holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Multibranch limit expanded to home/holding branches");
733
    is( $limit, "(homebranch: \"$branchcodes[0]\" OR homebranch: \"$branchcodes[1]\" OR holdingbranch: \"$branchcodes[0]\" OR holdingbranch: \"$branchcodes[1]\")", "Multibranch limit expanded to home/holding branches");
734
    is( $limit_desc, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1] OR holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Multibranch limit description correctly expanded");
734
    is( $limit_desc, "(homebranch: \"$branchcodes[0]\" OR homebranch: \"$branchcodes[1]\" OR holdingbranch: \"$branchcodes[0]\" OR holdingbranch: \"$branchcodes[1]\")", "Multibranch limit description correctly expanded");
735
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Multibranch limit cgi does not get expanded");
735
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Multibranch limit cgi does not get expanded");
736
736
737
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'homebranch');
737
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'homebranch');
738
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
738
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
739
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
739
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
740
    is( $limit, "(homebranch: CPL)", "branch limit expanded to home branch");
740
    is( $limit, "(homebranch: \"CPL\")", "branch limit expanded to home branch");
741
    is( $limit_desc, "(homebranch: CPL)", "limit description correctly expanded");
741
    is( $limit_desc, "(homebranch: \"CPL\")", "limit description correctly expanded");
742
    is( $limit_cgi, "&limit=branch%3ACPL", "limit cgi does not get expanded");
742
    is( $limit_cgi, "&limit=branch%3ACPL", "limit cgi does not get expanded");
743
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
743
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
744
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
744
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
745
    is( $limit, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1])", "branch limit expanded to home branch");
745
    is( $limit, "(homebranch: \"$branchcodes[0]\" OR homebranch: \"$branchcodes[1]\")", "branch limit expanded to home branch");
746
    is( $limit_desc, "(homebranch: $branchcodes[0] OR homebranch: $branchcodes[1])", "limit description correctly expanded");
746
    is( $limit_desc, "(homebranch: \"$branchcodes[0]\" OR homebranch: \"$branchcodes[1]\")", "limit description correctly expanded");
747
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded");
747
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded");
748
748
749
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'holdingbranch');
749
    t::lib::Mocks::mock_preference('SearchLimitLibrary', 'holdingbranch');
750
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
750
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
751
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
751
        $query_builder->build_query_compat( undef, undef, undef, [ "branch:CPL" ], undef, undef, undef, undef );
752
    is( $limit, "(holdingbranch: CPL)", "branch limit expanded to holding branch");
752
    is( $limit, "(holdingbranch: \"CPL\")", "branch limit expanded to holding branch");
753
    is( $limit_desc, "(holdingbranch: CPL)", "Limit description correctly expanded");
753
    is( $limit_desc, "(holdingbranch: \"CPL\")", "Limit description correctly expanded");
754
    is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded");
754
    is( $limit_cgi, "&limit=branch%3ACPL", "Limit cgi does not get expanded");
755
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
755
    ( undef, undef, undef, undef, undef, $limit, $limit_cgi, $limit_desc, undef ) =
756
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
756
        $query_builder->build_query_compat( undef, undef, undef, [ "multibranchlimit:$groupid" ], undef, undef, undef, undef );
757
    is( $limit, "(holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "branch limit expanded to holding branch");
757
    is( $limit, "(holdingbranch: \"$branchcodes[0]\" OR holdingbranch: \"$branchcodes[1]\")", "branch limit expanded to holding branch");
758
    is( $limit_desc, "(holdingbranch: $branchcodes[0] OR holdingbranch: $branchcodes[1])", "Limit description correctly expanded");
758
    is( $limit_desc, "(holdingbranch: \"$branchcodes[0]\" OR holdingbranch: \"$branchcodes[1]\")", "Limit description correctly expanded");
759
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded");
759
    is( $limit_cgi, "&limit=multibranchlimit%3A$groupid", "Limit cgi does not get expanded");
760
760
761
};
761
};
762
- 

Return to bug 31013