/usr/share/perl5/Plucene/Index/SegmentTermDocs.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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | package Plucene::Index::SegmentTermDocs;
=head1 NAME
Plucene::Index::SegmentTermDocs - Segment term docs
=head1 SYNOPSIS
my $seg_term_docs = Plucene::Index::SegmentTermDocs
->new(Plucene::Index::SegmentReader $seg_reader);
$seg_term_docs->seek($term);
$seg_term_docs->next;
$seg_term_docs->read;
$seg_term_docs->skip_to($target);
=head1 DESCRIPTION
This is the segment term docs class.
=head1 METHODS
=cut
use strict;
use warnings;
use IO::Handle;
use Carp qw/confess/;
use Plucene::Bitvector;
use base 'Class::Accessor::Fast';
__PACKAGE__->mk_accessors(
qw(parent freq_stream freq_count deleted_docs doc freq));
=head2 new
my $seg_term_docs = Plucene::Index::SegmentTermDocs
->new(Plucene::Index::SegmentReader $seg_reader);
This will create a new Plucene::Index::SegmentTermDocs object with the passed
segment reader.
=head2 parent / freq_stream / freq_count / deleted_docs / doc / freq
Get / set these attributes.
=cut
sub new {
my $self = shift;
my $seg_reader = shift;
return bless {
parent => $seg_reader,
freq_stream => $seg_reader->freq_stream, # listref
deleted_docs => $seg_reader->deleted_docs,
doc => 0,
} => $self;
}
=head2 seek
$seg_term_docs->seek($term);
=cut
sub seek {
my ($self, $ti) = @_;
# I object to this, but hey.
if ($ti->isa("Plucene::Index::Term")) {
$self->_seek($self->parent->{tis}->get($ti));
} else {
$self->_seek($ti);
}
}
sub _seek {
my ($self, $ti) = @_;
if (!$ti) {
$self->freq_count(0);
return;
}
$self->freq_count($ti->doc_freq);
$self->doc(0);
$self->{ptr} = $ti->freq_pointer; # offset in our array
}
=head2 skipping_doc
By default this does nothing. You may wish to override it to do something.
=cut
sub skipping_doc { }
sub _read_one {
my $self = shift;
my $doc_code = $self->freq_stream->[ $self->{ptr}++ ];
# A sequence that smacks of overoptimization
$self->{doc} += $doc_code >> 1;
if ($doc_code & 1) {
$self->freq(1);
} else {
$self->freq($self->freq_stream->[ $self->{ptr}++ ]);
}
$self->{freq_count}--;
}
=head2 next
$seg_term_docs->next;
=cut
sub next {
my $self = shift;
while (1) {
return if $self->freq_count == 0;
$self->_read_one();
last
unless $self->{deleted_docs}
&& $self->{deleted_docs}->get($self->{doc});
$self->skipping_doc;
}
return 1;
}
=head2 read
$seg_term_docs->read;
=cut
# Called by TermScorer and SegmentsTermDocs
sub read {
my $self = shift;
my (@docs, @freqs);
while ($self->{freq_count} > 0) {
$self->_read_one;
next
if $self->{deleted_docs}
&& $self->{deleted_docs}->get($self->{doc});
push @docs, $self->doc;
push @freqs, $self->freq;
}
return (\@docs, \@freqs);
}
=head2 skip_to
$seg_term_docs->skip_to($target);
=cut
sub skip_to {
my ($self, $target) = @_;
$self->next || return 0 while $target > $self->doc;
return 1;
}
1;
|