line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Search::Query::Dialect::Native; |
2
|
8
|
|
|
8
|
|
41
|
use Moo; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
52
|
|
3
|
|
|
|
|
|
|
extends 'Search::Query::Dialect'; |
4
|
8
|
|
|
8
|
|
2591
|
use Carp; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
587
|
|
5
|
8
|
|
|
8
|
|
43
|
use Data::Dump qw( dump ); |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
5357
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.306'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Search::Query::Dialect::Native - the default query dialect |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $query = Search::Query->parser->parse('foo'); |
16
|
|
|
|
|
|
|
print $query; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Search::Query::Dialect::Native is the default query dialect for Query |
21
|
|
|
|
|
|
|
objects returned by a Search::Query::Parser instance. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 METHODS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This class is a subclass of Search::Query::Dialect. Only new or overridden |
26
|
|
|
|
|
|
|
methods are documented here. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 stringify |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Returns the Query object as a normalized string. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub stringify { |
35
|
59
|
|
|
59
|
1
|
97
|
my $self = shift; |
36
|
59
|
|
66
|
|
|
263
|
my $tree = shift || $self; |
37
|
59
|
|
100
|
|
|
232
|
my $no_prefix = shift || 0; |
38
|
|
|
|
|
|
|
|
39
|
59
|
|
|
|
|
71
|
my @q; |
40
|
59
|
|
|
|
|
103
|
foreach my $prefix ( '+', '', '-' ) { |
41
|
177
|
100
|
|
|
|
463
|
next unless exists $tree->{$prefix}; |
42
|
62
|
|
|
|
|
79
|
for my $clause ( @{ $tree->{$prefix} } ) { |
|
62
|
|
|
|
|
138
|
|
43
|
97
|
100
|
|
|
|
314
|
push @q, |
44
|
|
|
|
|
|
|
( $no_prefix ? '' : $prefix ) |
45
|
|
|
|
|
|
|
. $self->stringify_clause($clause); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
59
|
|
|
|
|
522
|
return join " ", @q; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 stringify_clause( I ) |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Called by stringify() to handle each Clause in the Query tree. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub stringify_clause { |
59
|
97
|
|
|
97
|
1
|
133
|
my $self = shift; |
60
|
97
|
|
|
|
|
138
|
my $clause = shift; |
61
|
|
|
|
|
|
|
|
62
|
97
|
100
|
|
|
|
234
|
if ( $clause->{op} eq '()' ) { |
63
|
20
|
100
|
66
|
|
|
67
|
if ( $clause->has_children and $clause->has_children == 1 ) { |
64
|
4
|
|
|
|
|
12
|
return $self->stringify( $clause->{value}, 1 ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
else { |
67
|
16
|
|
|
|
|
52
|
return "(" . $self->stringify( $clause->{value} ) . ")"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
77
|
|
100
|
|
|
345
|
my $quote = $clause->quote || ""; |
72
|
77
|
|
|
|
|
147
|
my $value = $clause->value; |
73
|
77
|
|
100
|
|
|
337
|
my $proximity = $clause->proximity || ''; |
74
|
77
|
100
|
|
|
|
164
|
if ($proximity) { |
75
|
3
|
|
|
|
|
8
|
$proximity = '~' . $proximity; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# ranges |
79
|
77
|
100
|
100
|
|
|
349
|
if ( ref $value eq 'ARRAY' ) { |
|
|
100
|
|
|
|
|
|
80
|
3
|
100
|
66
|
|
|
23
|
if ( $value->[0] =~ m/[a-z]/i or $value->[1] =~ m/[a-z]/i ) { |
81
|
1
|
|
|
|
|
4
|
$value = join( qq/$quote$clause->{op}$quote/, |
82
|
|
|
|
|
|
|
( $value->[0], $value->[1] ) ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else { |
85
|
2
|
|
|
|
|
20
|
$value = join( qq/$quote $quote/, $value->[0] .. $value->[1] ); |
86
|
|
|
|
|
|
|
} |
87
|
3
|
100
|
|
|
|
15
|
if ( $clause->{op} eq '!..' ) { |
|
|
50
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return join( '', |
89
|
1
|
50
|
|
|
|
10
|
( defined $clause->{field} ? $clause->{field} : "" ), |
90
|
|
|
|
|
|
|
'!=', '(', $quote, $value, $quote, ')' ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif ( $clause->{op} eq '..' ) { |
93
|
|
|
|
|
|
|
return join( '', |
94
|
2
|
50
|
|
|
|
15
|
( defined $clause->{field} ? $clause->{field} : "" ), |
95
|
|
|
|
|
|
|
'=', '(', $quote, $value, $quote, ')' ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# NULL query |
100
|
|
|
|
|
|
|
elsif ( defined $clause->{field} and !defined $value ) { |
101
|
|
|
|
|
|
|
return sprintf( "%s %s NULL", |
102
|
2
|
100
|
|
|
|
24
|
$clause->{field}, ( $clause->{op} eq '=' ? 'is' : 'is not' ) ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
|
|
|
|
|
|
return join( '', |
106
|
|
|
|
|
|
|
( defined $clause->{field} ? $clause->{field} : "" ), |
107
|
72
|
100
|
|
|
|
460
|
$clause->{op}, $quote, $value, $quote, $proximity ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
__END__ |