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

(-)a/Koha/Z3950Responder/RPN.pm (-8 / +14 lines)
Lines 71-79 sub to_koha { Link Here
71
            $word =~ s/^[\,\.;:\\\/\"\'\-\=]+//g;
71
            $word =~ s/^[\,\.;:\\\/\"\'\-\=]+//g;
72
            $word =~ s/[\,\.;:\\\/\"\'\-\=]+$//g;
72
            $word =~ s/[\,\.;:\\\/\"\'\-\=]+$//g;
73
            next if (!$word);
73
            next if (!$word);
74
            $word = $self->escape($word);
74
            my @words;
75
            my @words;
75
            foreach my $field (@{$fields}) {
76
            foreach my $field (@{$fields}) {
76
                push(@words, "$field:($prefix$word$suffix)");
77
                push(@words, "$field:($quote$prefix$word$suffix$quote)");
77
            }
78
            }
78
            push (@terms, join(' OR ', @words));
79
            push (@terms, join(' OR ', @words));
79
        }
80
        }
Lines 81-95 sub to_koha { Link Here
81
    }
82
    }
82
83
83
    my @terms;
84
    my @terms;
85
    $term = $self->escape($term);
84
    foreach my $field (@{$fields}) {
86
    foreach my $field (@{$fields}) {
85
        push(@terms, "$field:($prefix$term$suffix)");
87
        push(@terms, "$field:($quote$prefix$term$suffix$quote)");
86
    }
88
    }
87
    return '(' . join(' OR ', @terms) . ')';
89
    return '(' . join(' OR ', @terms) . ')';
88
}
90
}
89
91
92
sub escape {
93
    my ($self, $term) = @_;
94
95
    $term =~ s/([()])/\\$1/g;
96
    return $term;
97
}
98
90
package Net::Z3950::RPN::And;
99
package Net::Z3950::RPN::And;
91
sub to_koha
100
sub to_koha {
92
{
93
    my ($self, $mappings) = @_;
101
    my ($self, $mappings) = @_;
94
102
95
    return '(' . $self->[0]->to_koha($mappings) . ' AND ' .
103
    return '(' . $self->[0]->to_koha($mappings) . ' AND ' .
Lines 97-104 sub to_koha Link Here
97
}
105
}
98
106
99
package Net::Z3950::RPN::Or;
107
package Net::Z3950::RPN::Or;
100
sub to_koha
108
sub to_koha {
101
{
102
    my ($self, $mappings) = @_;
109
    my ($self, $mappings) = @_;
103
110
104
    return '(' . $self->[0]->to_koha($mappings) . ' OR ' .
111
    return '(' . $self->[0]->to_koha($mappings) . ' OR ' .
Lines 106-113 sub to_koha Link Here
106
}
113
}
107
114
108
package Net::Z3950::RPN::AndNot;
115
package Net::Z3950::RPN::AndNot;
109
sub to_koha
116
sub to_koha {
110
{
111
    my ($self, $mappings) = @_;
117
    my ($self, $mappings) = @_;
112
118
113
    return '(' . $self->[0]->to_koha($mappings) . ' NOT ' .
119
    return '(' . $self->[0]->to_koha($mappings) . ' NOT ' .
(-)a/t/db_dependent/Koha/Z3950Responder/GenericSession.t (-3 / +2 lines)
Lines 68-74 subtest 'test_search' => sub { Link Here
68
    $search->mock('simple_search_compat', sub {
68
    $search->mock('simple_search_compat', sub {
69
        my ( $self, $query ) = @_;
69
        my ( $self, $query ) = @_;
70
70
71
        return (1, undef, 0) unless $query eq '((author:(author)) AND (title:(title)))';
71
        return (1, undef, 0) unless $query eq '((author:("author")) AND ((title:(title\(s\))) OR (title:(another))))';
72
        
72
        
73
        my @records = ($marc_record_1, $marc_record_2);
73
        my @records = ($marc_record_1, $marc_record_2);
74
        return (undef, \@records, 2);
74
        return (undef, \@records, 2);
Lines 97-103 subtest 'test_search' => sub { Link Here
97
    $Zconn->connect('127.0.0.1:42111', 0);
97
    $Zconn->connect('127.0.0.1:42111', 0);
98
    is($Zconn->errcode(), 0, 'Connection is successful: ' . $Zconn->errmsg());
98
    is($Zconn->errcode(), 0, 'Connection is successful: ' . $Zconn->errmsg());
99
99
100
    my $rs = $Zconn->search_pqf('@and @attr 1=1 author @attr 1=4 title');
100
    my $rs = $Zconn->search_pqf('@and @attr 1=1 @attr 4=1 author @or @attr 1=4 title(s) @attr 1=4 another');
101
    is($Zconn->errcode(), 0, 'Search is successful: ' . $Zconn->errmsg());
101
    is($Zconn->errcode(), 0, 'Search is successful: ' . $Zconn->errmsg());
102
102
103
    is($rs->size(), 2, 'Two results returned');
103
    is($rs->size(), 2, 'Two results returned');
104
- 

Return to bug 13937