line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
18
|
|
128
|
use strict; |
|
18
|
|
|
|
|
35
|
|
|
18
|
|
|
|
|
592
|
|
25
|
18
|
|
|
18
|
|
87
|
use warnings; |
|
18
|
|
|
|
|
29
|
|
|
18
|
|
|
|
|
575
|
|
26
|
|
|
|
|
|
|
|
27
|
18
|
|
|
18
|
|
12856
|
use Plucene::Document; |
|
18
|
|
|
|
|
47
|
|
|
18
|
|
|
|
|
201
|
|
28
|
18
|
|
|
18
|
|
11252
|
use Plucene::Document::Field; |
|
18
|
|
|
|
|
49
|
|
|
18
|
|
|
|
|
134
|
|
29
|
18
|
|
|
18
|
|
10252
|
use Plucene::Store::InputStream; |
|
18
|
|
|
|
|
58
|
|
|
18
|
|
|
|
|
9554
|
|
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
|
|
|
|
|
|
|
sub new { |
42
|
544
|
|
|
544
|
1
|
1449
|
my ($class, $dir, $seg, $fn) = @_; |
43
|
544
|
|
|
|
|
4508
|
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
|
1629
|
|
|
1629
|
1
|
15063
|
sub size { $_[0]->{size} } |
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
|
|
|
|
|
|
|
sub doc { |
70
|
499
|
|
|
499
|
1
|
768
|
my ($self, $n) = @_; |
71
|
499
|
|
|
|
|
2083
|
$self->{index}->seek($n * 8, 0); |
72
|
499
|
|
|
|
|
1777
|
my $pos = $self->{index}->read_long; |
73
|
499
|
|
|
|
|
1791
|
$self->{fields}->seek($pos, 0); |
74
|
499
|
|
|
|
|
1837
|
my $doc = Plucene::Document->new(); |
75
|
499
|
|
|
|
|
5874
|
for (1 .. $self->{fields}->read_vint) { |
76
|
820
|
|
|
|
|
5623
|
my $fi = $self->{field_infos}->{bynumber}->[ $self->{fields}->read_vint ]; |
77
|
820
|
|
|
|
|
2573
|
my $bits = $self->{fields}->read_byte; |
78
|
820
|
|
|
|
|
24895
|
$doc->add( |
79
|
|
|
|
|
|
|
bless { |
80
|
|
|
|
|
|
|
name => $fi->name, |
81
|
|
|
|
|
|
|
string => $self->{fields}->read_string, |
82
|
|
|
|
|
|
|
is_stored => 1, |
83
|
|
|
|
|
|
|
is_indexed => $fi->is_indexed, |
84
|
|
|
|
|
|
|
is_tokenized => (($bits & 1) != 0) # No, really |
85
|
|
|
|
|
|
|
} => 'Plucene::Document::Field' |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
} |
88
|
499
|
|
|
|
|
6544
|
return $doc; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |