line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
165384
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
110
|
|
2
|
2
|
|
|
2
|
|
16
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
625
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package KSx::Index::ByteBufDocWriter; |
5
|
2
|
|
|
2
|
|
18
|
use base qw( KinoSearch::Index::DataWriter ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
665
|
|
6
|
2
|
|
|
2
|
|
15
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
372
|
|
7
|
2
|
|
|
2
|
|
13
|
use Scalar::Util qw( blessed ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
123
|
|
8
|
2
|
|
|
2
|
|
14
|
use bytes; |
|
2
|
|
|
|
|
74
|
|
|
2
|
|
|
|
|
20
|
|
9
|
2
|
|
|
2
|
|
50
|
no bytes; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Inside-out member vars. |
12
|
|
|
|
|
|
|
our %field; |
13
|
|
|
|
|
|
|
our %width; |
14
|
|
|
|
|
|
|
our %outstream; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
4
|
|
|
4
|
1
|
100
|
my ( $either, %args ) = @_; |
18
|
4
|
|
|
|
|
12
|
my $width = delete $args{width}; |
19
|
4
|
|
|
|
|
7
|
my $field = delete $args{field}; |
20
|
4
|
|
|
|
|
67
|
my $self = $either->SUPER::new(%args); |
21
|
4
|
50
|
|
|
|
17
|
confess("Missing required param 'width'") unless defined $width; |
22
|
4
|
50
|
|
|
|
9
|
confess("Missing required param 'field'") unless defined $field; |
23
|
4
|
50
|
|
|
|
12
|
if ( $width < 1 ) { confess("'width' must be at least 1") } |
|
0
|
|
|
|
|
0
|
|
24
|
4
|
|
|
|
|
18
|
$field{$$self} = $field; |
25
|
4
|
|
|
|
|
8
|
$width{$$self} = $width; |
26
|
4
|
|
|
|
|
13
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _lazy_init { |
30
|
4
|
|
|
4
|
|
7
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Get outstream. Skip past non-doc #0. |
33
|
4
|
|
|
|
|
27
|
my $folder = $self->get_folder; |
34
|
4
|
|
|
|
|
38
|
my $filename = $self->get_segment->get_name . "/bytebufdocs.dat"; |
35
|
4
|
50
|
|
|
|
51
|
my $outstream = $outstream{$$self} = $folder->open_out($filename) |
36
|
|
|
|
|
|
|
or confess KinoSearch->error; |
37
|
4
|
|
|
|
|
13
|
my $nulls = "\0" x $width{$$self}; |
38
|
4
|
|
|
|
|
14
|
$outstream->print($nulls); |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
16
|
return $outstream; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub add_inverted_doc { |
44
|
13
|
|
|
13
|
1
|
529
|
my ( $self, %args ) = @_; |
45
|
13
|
|
66
|
|
|
49
|
my $outstream = $outstream{$$self} || _lazy_init($self); |
46
|
13
|
|
|
|
|
153
|
my $fields = $args{inverter}->get_doc->get_fields; |
47
|
13
|
|
|
|
|
30
|
my $width = $width{$$self}; |
48
|
13
|
|
|
|
|
16
|
my $field = $field{$$self}; |
49
|
13
|
50
|
|
|
|
41
|
if ( bytes::length( $fields->{$field} ) != $width ) { |
50
|
0
|
|
|
|
|
0
|
confess("Width of '$fields->{$field}' not $width"); |
51
|
|
|
|
|
|
|
} |
52
|
13
|
|
|
|
|
1428
|
$outstream->print( $fields->{$field} ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub add_segment { |
56
|
3
|
|
|
3
|
1
|
11
|
my ( $self, %args ) = @_; |
57
|
3
|
|
|
|
|
6
|
my $seg_reader = $args{reader}; |
58
|
3
|
|
|
|
|
6
|
my $doc_map = $args{doc_map}; |
59
|
3
|
|
|
|
|
17
|
my $doc_max = $seg_reader->doc_max; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Bail if the supplied segment is empty. */ |
62
|
3
|
50
|
|
|
|
9
|
return unless $doc_max; |
63
|
|
|
|
|
|
|
|
64
|
3
|
|
66
|
|
|
19
|
my $outstream = $outstream{$$self} || _lazy_init($self); |
65
|
3
|
|
|
|
|
31
|
my $doc_reader = $seg_reader->obtain("KinoSearch::Index::DocReader"); |
66
|
3
|
50
|
33
|
|
|
43
|
confess("Not a ByteBufDocReader") |
67
|
|
|
|
|
|
|
unless ( blessed($doc_reader) |
68
|
|
|
|
|
|
|
and $doc_reader->isa("KSx::Index::ByteBufDocReader") ); |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
12
|
for ( my $i = 1; $i <= $doc_max; $i++ ) { |
71
|
24
|
100
|
|
|
|
92
|
next unless $doc_map->get($i); |
72
|
21
|
|
|
|
|
25
|
my $buf; |
73
|
21
|
|
|
|
|
59
|
$doc_reader->read_record( $i, \$buf ); |
74
|
21
|
|
|
|
|
465
|
$outstream->print($buf); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub finish { |
79
|
4
|
|
|
4
|
1
|
100
|
my $self = shift; |
80
|
4
|
|
|
|
|
12
|
my $outstream = $outstream{$$self}; |
81
|
4
|
50
|
|
|
|
16
|
if ($outstream) { |
82
|
4
|
|
|
|
|
20
|
$outstream->close; |
83
|
4
|
|
|
|
|
18
|
my $segment = $self->get_segment; |
84
|
4
|
|
|
|
|
41
|
$segment->store_metadata( |
85
|
|
|
|
|
|
|
key => 'bytebufdocs', |
86
|
|
|
|
|
|
|
metadata => $self->metadata |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
4
|
|
|
4
|
1
|
44
|
sub format {1} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub DESTROY { |
94
|
4
|
|
|
4
|
|
511
|
my $self = shift; |
95
|
4
|
|
|
|
|
11
|
delete $field{$$self}; |
96
|
4
|
|
|
|
|
6
|
delete $width{$$self}; |
97
|
4
|
|
|
|
|
18
|
delete $outstream{$$self}; |
98
|
4
|
|
|
|
|
256
|
$self->SUPER::DESTROY; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |