Plucene/Search/DateFilter.pm

filter: Statementstmt 100% 42 / 42 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 83.3% 65 / 78 CC 11 SCAR 15.6
CC
11
Cov
85%
new
8.8
bits
5.0
BEGIN
1.0
CRAP 4.7
« Plucene/Index/SegmentMerger.pm ↑ Summary Plucene/Search/PhraseScorer/Exact.pm »
1 package Plucene::Search::DateFilter;
2 1 ▶use base 'Plucene::Search::Filter';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Plucene::Document::DateSerializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Bit::Vector::Minimal;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Plucene::Search::DateFilter - Restrict searches to given time periods
14  
15 =head1 SYNOPSIS
16  
17 my $filter = Plucene::Search::DateFilter->new({
18 field => "date",
19 from => Time::Piece $from,
20 to => Time::Piece $to
21 })
22 my $hits = $searcher->search($query, $filter);
23  
24 =head1 DESCRIPTION
25  
26 This class can restrict the results of a search to a set of dates. This
27 requires a field to have been indexed using
28 L<Plucene::Document::DateSerializer>. See the documentation for that module
29 for how to do this.
30  
31 =head1 METHODS
32  
33 =head2 new
34  
35 my $filter = Plucene::Search::DateFilter->new({
36 field => "date",
37 from => Time::Piece $from,
38 to => Time::Piece $to
39 })
40  
41 This creates a new filter. Either of C<from> or C<to> are optional.
42  
43 =cut
44  
45 1 ▶sub new {
Subroutine new: called CC=7 SCAR=21.8
Pod documented
46 1 my ($self, $args) = @_;
47 1 for my $arg (qw(from to)) {
48 2 ▶ next unless exists $args->{$arg};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{$arg} 0 2 2
49 croak "$arg argument was not a Time::Piece object"
50 2 ▶ unless UNIVERSAL::isa($args->{$arg}, "Time::Piece");
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($args->{$arg}, "Time::Piece") 0 2 2
51 }
52 1 ▶ croak "Need to pass a field" unless exists $args->{field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args->{"field"} 0 1 1
53 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
54 bless {
55 field => $args->{field},
56 from => freeze_date($args->{from} || Time::Piece->new(0)),
57 1 ▶ to => freeze_date($args->{to} || Time::Piece->new(~0)),
Condition33%2/6
$args->{'from'} || 'Time::Piece'->new(0)
l!l&&r!l&&!r
100
$args->{'to'} || 'Time::Piece'->new(18446744073709551615)
l!l&&r!l&&!r
100
MC/DC0%0/2
$args->{'from'} || 'Time::Piece'->new(0)
$args->{'from'} 'Time::Piece'->new(0)
MC/DC0%0/2
$args->{'to'} || 'Time::Piece'->new(18446744073709551615)
$args->{'to'} 'Time::Piece'->new(18446744073709551615)
Truth table33%1/3
A || B
A= $args->{'from'}B= 'Time::Piece'->new(0)
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $args->{'to'}B= 'Time::Piece'->new(18446744073709551615)
ABresult
1X1
011
000
58 }, $self;
59 }
60  
61 =head2 bits
62  
63 This is used by the searcher to iterate over the documents and return
64 a bitfield specifying which documents are included in the range.
65  
66 =cut
67  
68 1 ▶sub bits {
Subroutine bits: called CC=5 SCAR=16.2
Pod documented
69 1 my ($self, $reader) = @_;
70 1 my $bits = Bit::Vector::Minimal->new(size => $reader->max_doc);
71 my $enum = $reader->terms(
72 Plucene::Index::Term->new({
73 field => $self->{field},
74 1 text => $self->{from} }));
75 1 ▶ return $bits unless $enum->term;
Branch: 1 branch
BranchTrueFalseTotal
unless $enum->term 0 1 1
76 1 my $termdocs = $reader->term_docs;
77  
78 my $stop = Plucene::Index::Term->new({
79 field => $self->{field},
80 1 text => $self->{to} });
81 1 ▶ while ($enum->term->le($stop)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enum->term->le($stop)) 2 1 3
82 2 $termdocs->seek($enum->term);
83 2 ▶ $bits->set($termdocs->doc) while $termdocs->next;
Branch: 1 branch
BranchTrueFalseTotal
$termdocs->next and do { $bits->set($termdocs->doc) } 5 2 7
84 2 ▶ last unless $enum->next;
Branch: 1 branch
BranchTrueFalseTotal
unless $enum->next 0 2 2
85 }
86 1 return $bits;
87 }
88  
89 1 1;
« Plucene/Index/SegmentMerger.pm ↑ Summary Plucene/Search/PhraseScorer/Exact.pm »