| 1 | package Plucene::Index::SegmentsReader; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Plucene::Index::SegmentsReader - reads the segments | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | my $segs_reader = Plucene::Index::SegmentsReader | ||||||||||||||||||||||||||||
| 10 | ->new($dir, Plucene::Index::SegmentReader @readers); | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | my $num_docs = $segs_reader->num_docs; | ||||||||||||||||||||||||||||
| 13 | my $doc = $segs_reader->document($id); | ||||||||||||||||||||||||||||
| 14 | my $norms = $seg_reader->norms($field); | ||||||||||||||||||||||||||||
| 15 | my $doc_freq = $segs_reader->doc_freq($term); | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | my Plucene::Index::SegmentsTermEnum $term_enum | ||||||||||||||||||||||||||||
| 18 | = $segs_reader->terms($term); | ||||||||||||||||||||||||||||
| 19 | my Plucene::Index::SegmentsTermDocs $term_docs | ||||||||||||||||||||||||||||
| 20 | = $segs_reader->term_docs; | ||||||||||||||||||||||||||||
| 21 | my Plucene::Index::SegmentsTermPositions $term_positions | ||||||||||||||||||||||||||||
| 22 | = $segs_reader->term_positions; | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | if ($segs_reader->is_deleted($id)) { ... } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | This is the segments reader class. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 METHODS | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 18 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | 18 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 18 | ▶ | use List::Util qw(sum); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 18 | ▶ | use Plucene::Index::SegmentsTermEnum; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 18 | ▶ | use base qw(Plucene::Index::Reader Class::Accessor::Fast); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 18 | __PACKAGE__->mk_accessors(qw(max_doc)); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 18 | ▶ | use Memoize; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | 18 | memoize("norms"); # Saves messing with normsCache | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =head2 new | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | my $segs_reader = Plucene::Index::SegmentsReader | ||||||||||||||||||||||||||||
| 50 | ->new($dir, Plucene::Index::SegmentReader @readers); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | This will create a new Plucene::Index::SegmentsReader object with the passed | ||||||||||||||||||||||||||||
| 53 | directory and Plucene::Index::SegmentReader objects. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 54 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 58 | 54 | my ($class, $dir, @readers) = @_; | |||||||||||||||||||||||||||
| 59 | 54 | my $self = $class->SUPER::new($dir); | |||||||||||||||||||||||||||
| 60 | 54 | $self->{readers} = \@readers; | |||||||||||||||||||||||||||
| 61 | 54 | $self->{max_doc} = 0; | |||||||||||||||||||||||||||
| 62 | 54 | for my $reader (@readers) { | |||||||||||||||||||||||||||
| 63 | 168 | push @{ $self->{starts} }, $self->{max_doc}; | |||||||||||||||||||||||||||
| 64 | 168 | $self->{max_doc} += $reader->max_doc; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 54 | return $self; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =head2 num_docs | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | my $num_docs = $segs_reader->num_docs; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | This will return the number of documents in all the segments in the Reader. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub num_docs { | ||||||||||||||||||||||||||
|
Subroutine
num_docs: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 80 | 2 | ▶ | return $self->{num_docs} if exists $self->{num_docs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 1 | return $self->{num_docs} = sum(map $_->num_docs, @{ $self->{readers} }); | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head2 document | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | my $doc = $segs_reader->document($id); | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | This will return the document at the passed document id. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =cut | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 212 | ▶ | sub document { | ||||||||||||||||||||||||||
|
Subroutine
document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 212 | my ($self, $n) = @_; | |||||||||||||||||||||||||||
| 94 | 212 | my $i = $self->_reader_index($n); | |||||||||||||||||||||||||||
| 95 | 212 | return $self->{readers}[$i]->document($n - $self->{starts}[$i]); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =head2 is_deleted | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | if ($segs_reader->is_deleted($id)) { ... } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | sub is_deleted { | ||||||||||||||||||||||||||
|
Subroutine
is_deleted: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 105 | 2 | my ($self, $n) = @_; | |||||||||||||||||||||||||||
| 106 | 2 | my $i = $self->_reader_index($n); | |||||||||||||||||||||||||||
| 107 | 2 | return $self->{readers}[$i]->is_deleted($n - $self->{starts}[$i]); | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 1 | ▶ | sub _do_delete { | ||||||||||||||||||||||||||
|
Subroutine
_do_delete: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 111 | 1 | my ($self, $n) = @_; | |||||||||||||||||||||||||||
| 112 | 1 | delete $self->{num_docs}; # Invalidate cache | |||||||||||||||||||||||||||
| 113 | 1 | my $i = $self->_reader_index($n); | |||||||||||||||||||||||||||
| 114 | 1 | return $self->{readers}[$i]->_do_delete($n - $self->{starts}[$i]); | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 2 | ▶ | sub _do_close { | ||||||||||||||||||||||||||
|
Subroutine
_do_close: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 118 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 119 | 2 | $_->close for @{ $self->{readers} }; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 215 | ▶ | sub _reader_index { | ||||||||||||||||||||||||||
|
Subroutine
_reader_index: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 123 | 215 | my ($self, $n) = @_; | |||||||||||||||||||||||||||
| 124 | 215 | my ($lo, $hi) = (0, $#{ $self->{readers} }); | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # Binary search | ||||||||||||||||||||||||||||
| 127 | 215 | ▶ | while ($hi >= $lo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 418 | my $mid = int(($lo + $hi) / 2); | |||||||||||||||||||||||||||
| 129 | 418 | my $mid_val = $self->{starts}[$mid]; | |||||||||||||||||||||||||||
| 130 | 418 | ▶ | if ($n < $mid_val) { $hi = $mid - 1; } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 131 | 225 | elsif ($n > $mid_val) { $lo = $mid + 1; } | |||||||||||||||||||||||||||
| 132 | 29 | else { return $mid; } | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | 186 | return $hi; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =head2 norms | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | my $norms = $seg_reader->norms($field); | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | This returns the norms for the passed field. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 57 | ▶ | sub norms { | ||||||||||||||||||||||||||
|
Subroutine
norms: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 146 | 57 | my ($self, $field) = @_; | |||||||||||||||||||||||||||
| 147 | 57 | my $bytes = "\0" x $self->max_doc; | |||||||||||||||||||||||||||
| 148 | 57 | for my $i (0 .. $#{ $self->{readers} }) { | |||||||||||||||||||||||||||
| 149 | 173 | my $norm = $self->{readers}[$i]->norms($field); | |||||||||||||||||||||||||||
| 150 | 173 | substr($bytes, $self->{starts}[$i], length $norm) = $norm; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 57 | return $bytes; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =head2 terms | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | my Plucene::Index::SegmentsTermEnum $term_enum | ||||||||||||||||||||||||||||
| 158 | = $segs_reader->terms($term); | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | This will return the Plucene::Index::SegmentsTermEnum onject for the | ||||||||||||||||||||||||||||
| 161 | passed in term. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 3 | ▶ | sub terms { | ||||||||||||||||||||||||||
|
Subroutine
terms: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 3 | my ($self, $term) = @_; | |||||||||||||||||||||||||||
| 167 | return Plucene::Index::SegmentsTermEnum->new($self->{readers}, | ||||||||||||||||||||||||||||
| 168 | 3 | $self->{starts}, $term); | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head2 doc_freq | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | my $doc_freq = $segs_reader->doc_freq($term); | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | This returns the number of documents containing the passed term. | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 75 | ▶ | sub doc_freq { | ||||||||||||||||||||||||||
|
Subroutine
doc_freq: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 180 | 75 | my ($self, $term) = @_; | |||||||||||||||||||||||||||
| 181 | 75 | return sum map $_->doc_freq($term), @{ $self->{readers} }; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | =head2 term_docs | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | my Plucene::Index::SegmentsTermDocs $term_docs | ||||||||||||||||||||||||||||
| 187 | = $segs_reader->term_docs; | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | This will return the Plucene::Index::SegmentsTermDocs object. | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 72 | ▶ | sub term_docs { | ||||||||||||||||||||||||||
|
Subroutine
term_docs: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 194 | 72 | my $self = shift; | |||||||||||||||||||||||||||
| 195 | 72 | my $term = shift; | |||||||||||||||||||||||||||
| 196 | my $docs = | ||||||||||||||||||||||||||||
| 197 | 72 | Plucene::Index::SegmentsTermDocs->new($self->{readers}, $self->{starts}); | |||||||||||||||||||||||||||
| 198 | 72 | ▶ | if ($term) { $docs->seek($term) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 72 | return $docs; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =head2 term_positions | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | my Plucene::Index::SegmentsTermPositions $term_positions | ||||||||||||||||||||||||||||
| 206 | = $segs_reader->term_positions; | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | This will return the Plucene::Index::SegmentsTermPositions object. | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | =cut | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 9 | ▶ | sub term_positions { | ||||||||||||||||||||||||||
|
Subroutine
term_positions: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 214 | 9 | my $term = shift; | |||||||||||||||||||||||||||
| 215 | my $pos = | ||||||||||||||||||||||||||||
| 216 | Plucene::Index::SegmentsTermPositions->new($self->{readers}, | ||||||||||||||||||||||||||||
| 217 | 9 | $self->{starts}); | |||||||||||||||||||||||||||
| 218 | 9 | ▶ | if ($term) { $pos->seek($term) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 219 | 9 | return $pos; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | package Plucene::Index::SegmentsTermDocs; | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 81 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 225 | 81 | my ($class, $readers, $starts) = @_; | |||||||||||||||||||||||||||
| 226 | 81 | bless { | |||||||||||||||||||||||||||
| 227 | readers => $readers, | ||||||||||||||||||||||||||||
| 228 | starts => $starts, | ||||||||||||||||||||||||||||
| 229 | seg_term_docs => [], | ||||||||||||||||||||||||||||
| 230 | base => 0, | ||||||||||||||||||||||||||||
| 231 | pointer => 0, | ||||||||||||||||||||||||||||
| 232 | current => undef, | ||||||||||||||||||||||||||||
| 233 | }, $class; | ||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 151 | ▶ | sub doc { | ||||||||||||||||||||||||||
|
Subroutine
doc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 237 | 151 | my $self = shift; | |||||||||||||||||||||||||||
| 238 | 151 | return $self->{base} + $self->{current}->doc; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 140 | ▶ | sub freq { return shift->{current}->freq; } | ||||||||||||||||||||||||||
|
Subroutine
freq: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 79 | ▶ | sub seek { | ||||||||||||||||||||||||||
|
Subroutine
seek: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 244 | 79 | my ($self, $term) = @_; | |||||||||||||||||||||||||||
| 245 | 79 | $self->{term} = $term; | |||||||||||||||||||||||||||
| 246 | 79 | $self->{base} = 0; | |||||||||||||||||||||||||||
| 247 | 79 | $self->{pointer} = 0; | |||||||||||||||||||||||||||
| 248 | 79 | $self->{current} = undef; | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 318 | ▶ | sub _at_end { $_[0]->{pointer} >= @{ $_[0]->{readers} } } | ||||||||||||||||||||||||||
|
Subroutine
_at_end: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 243 | ▶ | sub _set_base_and_advance { | ||||||||||||||||||||||||||
|
Subroutine
_set_base_and_advance: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 254 | 243 | my $self = shift; | |||||||||||||||||||||||||||
| 255 | 243 | $self->{base} = $self->{starts}[ $self->{pointer} ]; | |||||||||||||||||||||||||||
| 256 | 243 | $self->{current} = $self->term_docs($self->{pointer}++); | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 185 | ▶ | sub next { | ||||||||||||||||||||||||||
|
Subroutine
next: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 260 | 185 | my $self = shift; | |||||||||||||||||||||||||||
| 261 | 185 | ▶ | return 1 if $self->{current} && $self->{current}->next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"current"} and $self->{"current"}->next
MC/DC100%2/2
$self->{"current"} and $self->{"current"}->next
$self->{"current"}
$self->{"current"}->next
Truth table100%3/3
A and B
A= $self->{"current"}B= $self->{"current"}->next
| |||||||||||||||||||||||||||||
| 262 | 34 | ▶ | unless ($self->_at_end) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 29 | $self->_set_base_and_advance; | |||||||||||||||||||||||||||
| 264 | 29 | return $self->next; | |||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||
| 266 | 5 | return 0; | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 169 | ▶ | sub read { | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 270 | 169 | my ($self) = @_; | |||||||||||||||||||||||||||
| 271 | 169 | my ($docs, $freqs) = ([], []); | |||||||||||||||||||||||||||
| 272 | 169 | while (1) { | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # Get a .current, somehow | ||||||||||||||||||||||||||||
| 275 | 383 | ▶ | while (!$self->{current}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 284 | ▶ | goto done if $self->_at_end; # Don't fall off | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 214 | $self->_set_base_and_advance; | |||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 313 | my ($new_docs, $new_freqs) = $self->{current}->read($docs, $freqs); | |||||||||||||||||||||||||||
| 281 | 313 | ▶ | if (!scalar @$new_docs) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | # It's empty | ||||||||||||||||||||||||||||
| 284 | 214 | undef $self->{current}; | |||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | # Correct the doc positions to the appropriate base | ||||||||||||||||||||||||||||
| 288 | 99 | $_ += $self->{base} for @$new_docs; | |||||||||||||||||||||||||||
| 289 | 99 | push @$docs, @$new_docs; | |||||||||||||||||||||||||||
| 290 | 99 | push @$freqs, @$new_freqs; | |||||||||||||||||||||||||||
| 291 | 99 | goto done; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 169 | done: return ($docs, $freqs); | |||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | 0 | ▶ | sub skip_to { | ||||||||||||||||||||||||||
|
Subroutine
skip_to: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 299 | 0 | my ($self, $target) = @_; | |||||||||||||||||||||||||||
| 300 | 0 | ▶ | $self->next || return while $target > $self->doc; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 301 | 0 | return 1; | |||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | 243 | ▶ | sub term_docs { | ||||||||||||||||||||||||||
|
Subroutine
term_docs: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 305 | 243 | my ($self, $i) = @_; | |||||||||||||||||||||||||||
| 306 | 243 | ▶ | return unless $self->{term}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | $self->{seg_term_docs}[$i] = $self->term_docs_r($self->{readers}[$i]) | ||||||||||||||||||||||||||||
| 308 | 243 | ▶ | unless exists $self->{seg_term_docs}[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 243 | my $result = $self->{seg_term_docs}[$i]; | |||||||||||||||||||||||||||
| 310 | 243 | $result->seek($self->{term}); | |||||||||||||||||||||||||||
| 311 | 243 | return $result; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 219 | ▶ | sub term_docs_r { | ||||||||||||||||||||||||||
|
Subroutine
term_docs_r: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 315 | 219 | my ($self, $reader) = @_; | |||||||||||||||||||||||||||
| 316 | 219 | return $reader->term_docs; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | package Plucene::Index::SegmentsTermPositions; | ||||||||||||||||||||||||||||
| 320 | 18 | ▶ | use base 'Plucene::Index::SegmentsTermDocs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 24 | ▶ | sub term_docs_r { | ||||||||||||||||||||||||||
|
Subroutine
term_docs_r: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 323 | 24 | my ($self, $reader) = @_; | |||||||||||||||||||||||||||
| 324 | 24 | return $reader->term_positions; | |||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 603 | ▶ | sub next_position { | ||||||||||||||||||||||||||
|
Subroutine
next_position: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 328 | 603 | return shift->{current}->next_position; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 18 | 1; | |||||||||||||||||||||||||||