line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
255166
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
128
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
104
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package KSx::Index::ByteBufDocReader; |
5
|
2
|
|
|
2
|
|
10
|
use base qw( KinoSearch::Index::DocReader ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
664
|
|
6
|
2
|
|
|
2
|
|
47500
|
use KinoSearch::Document::HitDoc; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
149
|
|
7
|
2
|
|
|
2
|
|
14
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
2854
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Inside-out member vars. |
10
|
|
|
|
|
|
|
our %width; |
11
|
|
|
|
|
|
|
our %field; |
12
|
|
|
|
|
|
|
our %instream; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
6
|
|
|
6
|
1
|
111
|
my ( $either, %args ) = @_; |
16
|
6
|
|
|
|
|
15
|
my $width = delete $args{width}; |
17
|
6
|
|
|
|
|
12
|
my $field = delete $args{field}; |
18
|
6
|
|
|
|
|
89
|
my $self = $either->SUPER::new(%args); |
19
|
6
|
50
|
|
|
|
19
|
confess("Missing required param 'width'") unless defined $width; |
20
|
6
|
50
|
|
|
|
17
|
confess("Missing required param 'field'") unless $field; |
21
|
6
|
50
|
|
|
|
14
|
if ( $width < 1 ) { confess("'width' must be at least 1") } |
|
0
|
|
|
|
|
0
|
|
22
|
6
|
|
|
|
|
23
|
$width{$$self} = $width; |
23
|
6
|
|
|
|
|
11
|
$field{$$self} = $field; |
24
|
|
|
|
|
|
|
|
25
|
6
|
|
|
|
|
39
|
my $segment = $self->get_segment; |
26
|
6
|
|
|
|
|
46
|
my $metadata = $self->get_segment->fetch_metadata("bytebufdocs"); |
27
|
6
|
50
|
|
|
|
16
|
if ($metadata) { |
28
|
6
|
50
|
|
|
|
21
|
if ( $metadata->{format} != 1 ) { |
29
|
0
|
|
|
|
|
0
|
confess("Unrecognized format: '$metadata->{format}'"); |
30
|
|
|
|
|
|
|
} |
31
|
6
|
|
|
|
|
29
|
my $filename = $segment->get_name . "/bytebufdocs.dat"; |
32
|
6
|
50
|
|
|
|
93
|
$instream{$$self} = $self->get_folder->open_in($filename) |
33
|
|
|
|
|
|
|
or confess KinoSearch->error; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
6
|
|
|
|
|
28
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub fetch_doc { |
40
|
3
|
|
|
3
|
1
|
175
|
my ( $self, $doc_id ) = @_; |
41
|
3
|
|
|
|
|
9
|
my $field = $field{$$self}; |
42
|
3
|
|
|
|
|
13
|
my %fields = ( $field => '' ); |
43
|
3
|
|
|
|
|
10
|
$self->read_record( $doc_id, \$fields{$field} ); |
44
|
3
|
|
|
|
|
192
|
return KinoSearch::Document::HitDoc->new( |
45
|
|
|
|
|
|
|
doc_id => $doc_id, |
46
|
|
|
|
|
|
|
fields => \%fields, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub read_record { |
51
|
24
|
|
|
24
|
0
|
40
|
my ( $self, $doc_id, $buf ) = @_; |
52
|
24
|
|
|
|
|
39
|
my $instream = $instream{$$self}; |
53
|
24
|
50
|
|
|
|
53
|
if ($instream) { |
54
|
24
|
|
|
|
|
33
|
my $width = $width{$$self}; |
55
|
24
|
|
|
|
|
80
|
$instream->seek( $width * $doc_id ); |
56
|
24
|
|
|
|
|
98
|
$instream->read( $$buf, $width ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub close { |
61
|
6
|
|
|
6
|
0
|
10
|
my $self = shift; |
62
|
6
|
|
|
|
|
11
|
delete $width{$$self}; |
63
|
6
|
|
|
|
|
42
|
delete $instream{$$self}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub DESTROY { |
67
|
6
|
|
|
6
|
|
245
|
my $self = shift; |
68
|
6
|
|
|
|
|
10
|
delete $width{$$self}; |
69
|
6
|
|
|
|
|
9
|
delete $field{$$self}; |
70
|
6
|
|
|
|
|
19
|
delete $instream{$$self}; |
71
|
6
|
|
|
|
|
295
|
$self->SUPER::DESTROY; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |