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