| 1 | package Plucene::Index::SegmentInfos; | ||||||||||||
| 2 | |||||||||||||
| 3 | =head1 NAME | ||||||||||||
| 4 | |||||||||||||
| 5 | Plucene::Index::SegmentInfos - A collection of SegmentInfo objects | ||||||||||||
| 6 | |||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||
| 8 | |||||||||||||
| 9 | my $segmentinfos = Plucene::Index::SegmentInfos->new; | ||||||||||||
| 10 | |||||||||||||
| 11 | $segmentinfos->read($dir); | ||||||||||||
| 12 | $segmentinfos->write($dir); | ||||||||||||
| 13 | |||||||||||||
| 14 | $segmentinfos->add_element(Plucene::Index::SegmentInfo $segment_info); | ||||||||||||
| 15 | |||||||||||||
| 16 | my Plucene::Index::SegmentInfo @segment_info | ||||||||||||
| 17 | = $segmentinfos->segments; | ||||||||||||
| 18 | |||||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||||
| 20 | |||||||||||||
| 21 | This is a collection of Plucene::Index::SegmentInfo objects | ||||||||||||
| 22 | |||||||||||||
| 23 | =head1 METHODS | ||||||||||||
| 24 | |||||||||||||
| 25 | =cut | ||||||||||||
| 26 | |||||||||||||
| 27 | 18 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 18 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | |||||||||||||
| 30 | 18 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 31 | |||||||||||||
| 32 | 18 | ▶ | use Plucene::Index::SegmentInfo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 33 | 18 | ▶ | use Plucene::Store::InputStream; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | 18 | ▶ | use Plucene::Store::OutputStream; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | 18 | ▶ | use File::Slurp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 36 | |||||||||||||
| 37 | =head2 new | ||||||||||||
| 38 | |||||||||||||
| 39 | my $segmentinfos = Plucene::Index::SegmentInfos->new; | ||||||||||||
| 40 | |||||||||||||
| 41 | This will create a new (empty) Plucene::Index::SegmentInfos object. | ||||||||||||
| 42 | |||||||||||||
| 43 | =cut | ||||||||||||
| 44 | |||||||||||||
| 45 | 213 | ▶ | sub new { bless { segments => [] }, shift } | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 46 | |||||||||||||
| 47 | =head2 read | ||||||||||||
| 48 | |||||||||||||
| 49 | $segmentinfos->read($dir); | ||||||||||||
| 50 | |||||||||||||
| 51 | This will read the segments file from the passed directory. | ||||||||||||
| 52 | |||||||||||||
| 53 | =cut | ||||||||||||
| 54 | |||||||||||||
| 55 | 196 | ▶ | sub read { | ||||||||||
|
Subroutine
read: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 56 | 196 | my ($self, $directory) = @_; | |||||||||||
| 57 | 196 | my ($count, @unpack) = unpack "NN/(w/aN)", read_file("$directory/segments"); | |||||||||||
| 58 | 196 | my @segs; | |||||||||||
| 59 | 196 | ▶ | while (my ($name, $count) = splice @unpack, 0, 2) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 310 | push @segs, | |||||||||||
| 61 | bless { | ||||||||||||
| 62 | name => $name, | ||||||||||||
| 63 | doc_count => $count, | ||||||||||||
| 64 | dir => $directory, | ||||||||||||
| 65 | } => 'Plucene::Index::SegmentInfo'; | ||||||||||||
| 66 | } | ||||||||||||
| 67 | 196 | $self->{segments} = \@segs; | |||||||||||
| 68 | 196 | $self->{counter} = $count; | |||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | =head2 write | ||||||||||||
| 72 | |||||||||||||
| 73 | $segmentinfos->write($dir); | ||||||||||||
| 74 | |||||||||||||
| 75 | This will write the segments info file out. | ||||||||||||
| 76 | |||||||||||||
| 77 | =cut | ||||||||||||
| 78 | |||||||||||||
| 79 | 56 | ▶ | sub write { | ||||||||||
|
Subroutine
write: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 80 | 56 | my ($self, $directory) = @_; | |||||||||||
| 81 | 56 | my $segfile = "$directory/segments"; | |||||||||||
| 82 | 56 | my $tempfile = "${segfile}.new"; | |||||||||||
| 83 | 56 | my @segs = $self->segments; | |||||||||||
| 84 | 56 | my $template = "NN" . ("w/a*N" x @segs); | |||||||||||
| 85 | my $packed = pack $template, $self->{counter} || 0, scalar @segs, | ||||||||||||
| 86 | 56 | ▶ | map { $_->name => $_->doc_count } @segs; | ||||||||||
|
Condition100%2/2
$self->{'counter'} || 0
MC/DC100%1/1
$self->{'counter'} || 0
$self->{'counter'}
Truth table100%2/2
A
A= $self->{'counter'}
| |||||||||||||
| 87 | 56 | write_file($tempfile => $packed); | |||||||||||
| 88 | 56 | rename($tempfile => $segfile); | |||||||||||
| 89 | } | ||||||||||||
| 90 | |||||||||||||
| 91 | =head2 add_element | ||||||||||||
| 92 | |||||||||||||
| 93 | $segmentinfos->add_element(Plucene::Index::SegmentInfo $segment_info); | ||||||||||||
| 94 | |||||||||||||
| 95 | This will add the passed Plucene::Index::SegmentInfo object.. | ||||||||||||
| 96 | |||||||||||||
| 97 | =cut | ||||||||||||
| 98 | |||||||||||||
| 99 | 257 | ▶ | sub add_element { push @{ $_[0]->{segments} }, $_[1] } | ||||||||||
|
Subroutine
add_element: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 100 | |||||||||||||
| 101 | =head2 info | ||||||||||||
| 102 | |||||||||||||
| 103 | my Plucene::Index::SegmentInfo $info | ||||||||||||
| 104 | = $segmentinfos->info($segment_no); | ||||||||||||
| 105 | |||||||||||||
| 106 | This will return the Plucene::Index::SegmentInfo object at the passed | ||||||||||||
| 107 | segment number. | ||||||||||||
| 108 | |||||||||||||
| 109 | =cut | ||||||||||||
| 110 | |||||||||||||
| 111 | 1841 | ▶ | sub info { $_[0]->{segments}->[ $_[1] ] } | ||||||||||
|
Subroutine
info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 112 | |||||||||||||
| 113 | =head2 segments | ||||||||||||
| 114 | |||||||||||||
| 115 | my Plucene::Index::SegmentInfo @segment_info | ||||||||||||
| 116 | = $segmentinfos->segments; | ||||||||||||
| 117 | |||||||||||||
| 118 | This returns all the Plucene::Index::SegmentInfo onjects in this segment. | ||||||||||||
| 119 | |||||||||||||
| 120 | =cut | ||||||||||||
| 121 | |||||||||||||
| 122 | 672 | ▶ | sub segments { @{ $_[0]->{segments} } } | ||||||||||
|
Subroutine
segments: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 123 | |||||||||||||
| 124 | 18 | 1; | |||||||||||