Bug 9239 QA follow-up: remove stray debug code
[koha.git] / Koha / QueryParser / Driver / PQF / query_plan / node.pm
1 package Koha::QueryParser::Driver::PQF::query_plan::node;
2 use base 'OpenILS::QueryParser::query_plan::node';
3
4 use strict;
5 use warnings;
6
7 =head1 NAME
8
9 Koha::QueryParser::Driver::PQF::query_plan::node - node subclass for PQF driver
10
11 =head1 FUNCTIONS
12
13 =head2 Koha::QueryParser::Driver::PQF::query_plan::node::target_syntax
14
15     my $pqf = $node->target_syntax($server);
16
17 Transforms an OpenILS::QueryParser::query_plan::node object into PQF. Do not use directly.
18
19 =cut
20
21 sub target_syntax {
22     my ($self, $server) = @_;
23     my $pqf = '';
24     my $atom_content;
25     my $atom_count = 0;
26     my @fields = ();
27     my $fieldobj;
28     my $relbump;
29
30     if (scalar(@{$self->fields})) {
31         foreach my $field (@{$self->fields}) {
32             $fieldobj = $self->plan->QueryParser->bib1_mapping_by_name('field', $self->classname, $field, $server);
33             $relbump = $self->plan->QueryParser->bib1_mapping_by_name('relevance_bump', $self->classname, $field, $server);
34             if ($relbump) {
35                 $fieldobj->{'attr_string'} .= ' ' . $relbump->{'attr_string'};
36             }
37             push @fields, $fieldobj unless (!defined($fieldobj) || ($field eq $self->classname && @{$self->fields} > 1));
38         }
39     } else {
40         $fieldobj = $self->plan->QueryParser->bib1_mapping_by_name('field', $self->classname, $self->classname, $server);
41         my $relbumps = $self->plan->QueryParser->bib1_mapping_by_name('relevance_bump', $self->classname, '', $server);
42         push @fields, $fieldobj;
43         if ($relbumps) {
44             foreach my $field (keys %$relbumps) {
45                 $relbump = $relbumps->{$field};
46                 $fieldobj = $self->plan->QueryParser->bib1_mapping_by_name('field', $relbump->{'classname'}, $relbump->{'field'}, $server);
47                 $fieldobj->{'attr_string'} ||= '';
48                 $fieldobj->{'attr_string'} .= ' ' . $relbump->{$server}{'attr_string'} if $relbump->{$server}{'attr_string'};
49                 push @fields, $fieldobj;
50             }
51         }
52     }
53
54     if (@{$self->phrases}) {
55         foreach my $phrase (@{$self->phrases}) {
56             if ($phrase) {
57                 $pqf .= ' @or ' x (scalar(@fields) - 1);
58                 foreach my $attributes (@fields) {
59                     $pqf .= $attributes->{'attr_string'} . ($attributes->{'4'} ? '' : ' @attr 4=1') . ' "' . $phrase . '" ';
60                 }
61                 $atom_count++;
62             }
63         }
64     } else {
65         foreach my $atom (@{$self->query_atoms}) {
66             if (ref($atom)) {
67                 $atom_content = $atom->target_syntax($server);
68                 if ($atom_content) {
69                     $pqf .= ' @or ' x (scalar(@fields) - 1);
70                     foreach my $attributes (@fields) {
71                         $attributes->{'attr_string'} ||= '';
72                         $pqf .= $attributes->{'attr_string'} . ($attributes->{'4'} ? '' : ' @attr 4=6 ') . $atom_content . ' ';
73                     }
74                     $atom_count++;
75                 }
76             }
77         }
78     }
79     $pqf = (OpenILS::QueryParser::_util::default_joiner eq '|' ? ' @or ' : ' @and ') x ($atom_count - 1) . $pqf;
80     return ($self->negate ? '@not @attr 1=_ALLRECORDS @attr 2=103 "" ' : '') . $pqf;
81 }
82
83 1;