Plucene/Index/FieldsReader.pm

filter: Statementstmt 100% 29 / 29 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 100% 40 / 40 CC 2 SCAR 2.0
CC
2
Cov
100%
doc
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.2
« Plucene/Analysis/Analyzer.pm ↑ Summary Plucene/Analysis/TokenFilter.pm »
1 package Plucene::Index::FieldsReader;
2  
3 =head1 NAME
4  
5 Plucene::Index::FieldsReader - read Fields in a Document
6  
7 =head1 SYNOPSIS
8  
9 my $reader = Plucene::Index::FieldsReader->new(
10 $dir_name, $segment, $field_infos);
11  
12 my Plucene::Document $doc = $reader->doc($offset);
13  
14 my $size = $reader->size;
15  
16 =head1 DESCRIPTION
17  
18 This class gives access to documents within the index.
19  
20 =head1 METHODS
21  
22 =cut
23  
24 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 18 ▶use Plucene::Document;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 18 ▶use Plucene::Document::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 18 ▶use Plucene::Store::InputStream;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 =head2 new
32  
33 my $reader = Plucene::Index::FieldsReader->new(
34 $dir_name, $segment, $field_infos);
35  
36 This will create a new Plucene::Index::FieldsReader with the passed in
37 directory name, segment and field infos.
38
39 =cut
40  
41 583 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
42 583 my ($class, $dir, $seg, $fn) = @_;
43 583 bless {
44 field_infos => $fn,
45 fields => Plucene::Store::InputStream->new("$dir/$seg.fdt"),
46 index => Plucene::Store::InputStream->new("$dir/$seg.fdx"),
47 size => ((-s "$dir/$seg.fdx") / 8) }, $class;
48 }
49  
50 =head2 size
51  
52 my $size = $reader->size;
53  
54 This returns the size.
55  
56 =cut
57  
58 1716 ▶sub size { $_[0]->{size} }
Subroutine size: called CC=1 SCAR=0.0
Pod documented
59  
60 =head2 doc
61  
62 my Plucene::Document $doc = $reader->doc($offset);
63  
64 This will return the Plucene::Document object found at the passed in
65 position.
66  
67 =cut
68  
69 601 ▶sub doc {
Subroutine doc: called CC=2 SCAR=6.9
Pod documented
70 601 my ($self, $n) = @_;
71 601 $self->{index}->seek($n * 8, 0);
72 601 my $pos = $self->{index}->read_long;
73 601 $self->{fields}->seek($pos, 0);
74 601 my $doc = Plucene::Document->new();
75 601 for (1 .. $self->{fields}->read_vint) {
76 1126 my $fi = $self->{field_infos}->{bynumber}->[ $self->{fields}->read_vint ];
77 1126 my $bits = $self->{fields}->read_byte;
78 $doc->add(
79 bless {
80 name => $fi->name,
81 string => $self->{fields}->read_string,
82 1126 is_stored => 1,
83 is_indexed => $fi->is_indexed,
84 is_tokenized => (($bits & 1) != 0) # No, really
85 } => 'Plucene::Document::Field'
86 );
87 }
88 601 return $doc;
89 }
90  
91 18 1;
« Plucene/Analysis/Analyzer.pm ↑ Summary Plucene/Analysis/TokenFilter.pm »