line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package LucyX::Search::AnyTermQuery; |
2
|
1
|
|
|
1
|
|
25171
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
3
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw( Lucy::Search::Query ); |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
727
|
|
5
|
|
|
|
|
|
|
use Carp; |
6
|
|
|
|
|
|
|
use Scalar::Util qw( blessed ); |
7
|
|
|
|
|
|
|
use LucyX::Search::AnyTermCompiler; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.005'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
LucyX::Search::AnyTermQuery - Lucy query extension for not NULL values |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $query = LucyX::Search::AnyTermQuery->new( |
18
|
|
|
|
|
|
|
field => 'color', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
my $hits = $searcher->hits( query => $query ); |
21
|
|
|
|
|
|
|
# $hits == documents where the 'color' field is not empty |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
LucyX::Search::AnyTermQuery extends the |
26
|
|
|
|
|
|
|
Lucy::QueryParser syntax to support NULL values. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 METHODS |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This class is a subclass of Lucy::Search::Query. Only new or overridden |
31
|
|
|
|
|
|
|
methods are documented here. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Inside-out member vars |
36
|
|
|
|
|
|
|
my %field; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 new( I ) |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Create a new AnyTermQuery object. I must contain key/value pair |
41
|
|
|
|
|
|
|
for C. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
|
|
|
|
|
|
my ( $class, %args ) = @_; |
47
|
|
|
|
|
|
|
my $field = delete $args{field}; |
48
|
|
|
|
|
|
|
my $self = $class->SUPER::new(%args); |
49
|
|
|
|
|
|
|
confess("'field' param is required") |
50
|
|
|
|
|
|
|
unless defined $field; |
51
|
|
|
|
|
|
|
$field{$$self} = $field; |
52
|
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 get_field |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Retrieve the value set in new(). |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get_field { my $self = shift; return $field{$$self} } |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub DESTROY { |
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
delete $field{$$self}; |
66
|
|
|
|
|
|
|
$self->SUPER::DESTROY; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 equals |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Returns true (1) if the object represents the same kind of query |
72
|
|
|
|
|
|
|
clause as another AnyTermQuery. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
NOTE: Currently a AnyTermQuery and a NullTermQuery object will |
75
|
|
|
|
|
|
|
evaluate as equal if they have the same field. This is a bug. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub equals { |
80
|
|
|
|
|
|
|
my ( $self, $other ) = @_; |
81
|
|
|
|
|
|
|
return 0 unless blessed($other); |
82
|
|
|
|
|
|
|
return 0 |
83
|
|
|
|
|
|
|
unless $other->isa( ref $self ); |
84
|
|
|
|
|
|
|
return $self->get_field eq $other->get_field; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 to_string |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns the query clause the object represents. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub to_string { |
94
|
|
|
|
|
|
|
my $self = shift; |
95
|
|
|
|
|
|
|
return sprintf( "(NOT %s:NULL)", $self->get_field ); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 make_compiler |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Returns a LucyX::Search::NullCompiler object. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub make_compiler { |
105
|
|
|
|
|
|
|
my $self = shift; |
106
|
|
|
|
|
|
|
my %args = @_; |
107
|
|
|
|
|
|
|
$args{parent} = $self; |
108
|
|
|
|
|
|
|
return LucyX::Search::AnyTermCompiler->new(%args); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# TODO should our compiler call this in make_matcher() ? |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# unlike Search::Query synopsis, normalize() |
113
|
|
|
|
|
|
|
# is called internally in $compiler. |
114
|
|
|
|
|
|
|
# This should be fixed in a C re-write. |
115
|
|
|
|
|
|
|
#$compiler->normalize unless $subordinate; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#return $compiler; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
__END__ |