AnyTermQuery.pm

filter: Statementstmt 85.7% 36 / 42 Branchbran 16.6% 1 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 10 / 12 Podpod 100% 5 / 5 totaltotal 80.0% 52 / 65 CC 4 SCAR 12.2
CC
4
Cov
77%
equals
12.0
new
2.0
to_string
2.0
CRAP 3.4
« AnyTermCompiler.pm ↑ Summary NullTermQuery.pm »
1 package LucyX::Search::AnyTermQuery;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base qw( Lucy::Search::Query );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use LucyX::Search::AnyTermCompiler;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.006';
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 3 my %field;
37  
38 =head2 new( I<args> )
39  
40 Create a new AnyTermQuery object. I<args> must contain key/value pair
41 for C<field>.
42  
43 =cut
44  
45 6 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
46 6 my ( $class, %args ) = @_;
47 6 my $field = delete $args{field};
48 6 my $self = $class->SUPER::new(%args);
49 6 ▶ confess("'field' param is required")
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field 0 6 6
50 unless defined $field;
51 6 $field{$$self} = $field;
52 6 return $self;
53 }
54  
55 =head2 get_field
56  
57 Retrieve the value set in new().
58  
59 =cut
60  
61 6 ▶sub get_field { my $self = shift; return $field{$$self} }
Subroutine get_field: called CC=1 SCAR=0.0
Pod documented
62  
63 6 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
64 6 my $self = shift;
65 6 delete $field{$$self};
66 6 $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 0 ▶sub equals {
Subroutine equals: not called CC=3 SCAR=24.8
Pod documented
80 0 my ( $self, $other ) = @_;
81 0 ▶ return 0 unless blessed($other);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) 0 0 0
82 0 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa(ref $self) 0 0 0
83 unless $other->isa( ref $self );
84 0 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 0 ▶sub to_string {
Subroutine to_string: not called CC=1 SCAR=6.9
Pod documented
94 0 my $self = shift;
95 0 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 6 ▶sub make_compiler {
Subroutine make_compiler: called CC=1 SCAR=0.0
Pod documented
105 6 my $self = shift;
106 6 my %args = @_;
107 6 $args{parent} = $self;
108 6 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 3 1;
121  
122 __END__
« AnyTermCompiler.pm ↑ Summary NullTermQuery.pm »