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

(-)a/Koha/Z3950Responder/RPN.pm (-8 / +12 lines)
Lines 42-48 sub to_koha { Link Here
42
    my $attrs = $self->{'attributes'};
42
    my $attrs = $self->{'attributes'};
43
    my $fields = $mappings->{use}{default} // '_all';
43
    my $fields = $mappings->{use}{default} // '_all';
44
    my $split = 0;
44
    my $split = 0;
45
    my $quote = '';
46
    my $prefix = '';
45
    my $prefix = '';
47
    my $suffix = '';
46
    my $suffix = '';
48
    my $term = $self->{'term'};
47
    my $term = $self->{'term'};
Lines 54-60 sub to_koha { Link Here
54
                $fields = $mappings->{use}{$use} if defined $mappings->{use}{$use};
53
                $fields = $mappings->{use}{$use} if defined $mappings->{use}{$use};
55
            } elsif ($attr->{'attributeType'} == 4) { # structure
54
            } elsif ($attr->{'attributeType'} == 4) { # structure
56
                $split = 1 if ($attr->{'attributeValue'} == 2);
55
                $split = 1 if ($attr->{'attributeValue'} == 2);
57
                $quote = '"' if ($attr->{'attributeValue'} == 1);
58
            } elsif ($attr->{'attributeType'} == 5) { # truncation
56
            } elsif ($attr->{'attributeType'} == 5) { # truncation
59
                my $truncation = $attr->{'attributeValue'};
57
                my $truncation = $attr->{'attributeValue'};
60
                $prefix = '*' if ($truncation == 2 || $truncation == 3);
58
                $prefix = '*' if ($truncation == 2 || $truncation == 3);
Lines 71-76 sub to_koha { Link Here
71
            $word =~ s/^[\,\.;:\\\/\"\'\-\=]+//g;
69
            $word =~ s/^[\,\.;:\\\/\"\'\-\=]+//g;
72
            $word =~ s/[\,\.;:\\\/\"\'\-\=]+$//g;
70
            $word =~ s/[\,\.;:\\\/\"\'\-\=]+$//g;
73
            next if (!$word);
71
            next if (!$word);
72
            $word = $self->escape($word);
74
            my @words;
73
            my @words;
75
            foreach my $field (@{$fields}) {
74
            foreach my $field (@{$fields}) {
76
                push(@words, "$field:($prefix$word$suffix)");
75
                push(@words, "$field:($prefix$word$suffix)");
Lines 81-95 sub to_koha { Link Here
81
    }
80
    }
82
81
83
    my @terms;
82
    my @terms;
83
    $term = $self->escape($term);
84
    foreach my $field (@{$fields}) {
84
    foreach my $field (@{$fields}) {
85
        push(@terms, "$field:($prefix$term$suffix)");
85
        push(@terms, "$field:($prefix$term$suffix)");
86
    }
86
    }
87
    return '(' . join(' OR ', @terms) . ')';
87
    return '(' . join(' OR ', @terms) . ')';
88
}
88
}
89
89
90
sub escape {
91
    my ($self, $term) = @_;
92
93
    $term =~ s/([()])/\\$1/g;
94
    return $term;
95
}
96
90
package Net::Z3950::RPN::And;
97
package Net::Z3950::RPN::And;
91
sub to_koha
98
sub to_koha {
92
{
93
    my ($self, $mappings) = @_;
99
    my ($self, $mappings) = @_;
94
100
95
    return '(' . $self->[0]->to_koha($mappings) . ' AND ' .
101
    return '(' . $self->[0]->to_koha($mappings) . ' AND ' .
Lines 97-104 sub to_koha Link Here
97
}
103
}
98
104
99
package Net::Z3950::RPN::Or;
105
package Net::Z3950::RPN::Or;
100
sub to_koha
106
sub to_koha {
101
{
102
    my ($self, $mappings) = @_;
107
    my ($self, $mappings) = @_;
103
108
104
    return '(' . $self->[0]->to_koha($mappings) . ' OR ' .
109
    return '(' . $self->[0]->to_koha($mappings) . ' OR ' .
Lines 106-113 sub to_koha Link Here
106
}
111
}
107
112
108
package Net::Z3950::RPN::AndNot;
113
package Net::Z3950::RPN::AndNot;
109
sub to_koha
114
sub to_koha {
110
{
111
    my ($self, $mappings) = @_;
115
    my ($self, $mappings) = @_;
112
116
113
    return '(' . $self->[0]->to_koha($mappings) . ' NOT ' .
117
    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