/usr/lib/perl5/KinoSearch1/Index/FieldsWriter.pm is in libkinosearch1-perl 1.00-1build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | package KinoSearch1::Index::FieldsWriter;
use strict;
use warnings;
use KinoSearch1::Util::ToolSet;
use base qw( KinoSearch1::Util::Class );
BEGIN {
__PACKAGE__->init_instance_vars(
# constructor params / members
invindex => undef,
seg_name => undef,
# members
fdata_stream => undef,
findex_stream => undef,
);
}
use Compress::Zlib qw( compress );
sub init_instance {
my $self = shift;
my $invindex = $self->{invindex};
# open an index stream and a data stream.
my $fdx_file = "$self->{seg_name}.fdx";
my $fdt_file = "$self->{seg_name}.fdt";
for ( $fdx_file, $fdt_file, ) {
$invindex->delete_file($_) if $invindex->file_exists($_);
}
$self->{findex_stream} = $invindex->open_outstream($fdx_file);
$self->{fdata_stream} = $invindex->open_outstream($fdt_file);
}
sub add_doc {
my ( $self, $doc ) = @_;
# record the data stream's current file pointer in the index.
$self->{findex_stream}->lu_write( 'Q', $self->{fdata_stream}->tell );
# only store fields marked as "stored"
my @stored = sort { $a->get_field_num <=> $b->get_field_num }
grep $_->get_stored, $doc->get_fields;
# add the number of stored fields in the Doc
my @to_write = ( scalar @stored );
# add flag bits and value for each stored field
for (@stored) {
push @to_write, ( $_->get_field_num, $_->get_fdt_bits );
push @to_write, $_->get_compressed
? compress( $_->get_value )
: $_->get_value;
push @to_write, $_->get_tv_string;
}
# write out data
my $lu_template = 'V' . ( 'VaTT' x scalar @stored );
$self->{fdata_stream}->lu_write( $lu_template, @to_write );
}
sub add_segment {
my ( $self, $seg_reader, $doc_map, $field_num_map ) = @_;
my ( $findex_stream, $fdata_stream )
= @{$self}{qw( findex_stream fdata_stream )};
my $fields_reader = $seg_reader->get_fields_reader;
my $max = $seg_reader->max_doc;
return unless $max;
$max -= 1;
for my $orig ( 0 .. $max ) {
# if the doc isn't deleted, copy it to the new seg
next unless defined $doc_map->get($orig);
# write pointer
$findex_stream->lu_write( 'Q', $fdata_stream->tell );
# retrieve all fields
my ( $num_fields, $all_data ) = $fields_reader->fetch_raw($orig);
# write number of fields
$fdata_stream->lu_write( 'V', $num_fields );
# write data for each field
for ( 1 .. $num_fields ) {
my ( $field_num, @some_data ) = splice( @$all_data, 0, 4 );
$fdata_stream->lu_write( 'VaTT', $field_num_map->get($field_num),
@some_data );
}
}
}
sub finish {
my $self = shift;
$self->{fdata_stream}->close;
$self->{findex_stream}->close;
}
1;
__END__
=begin devdocs
=head1 NAME
KinoSearch1::Index::FieldsWriter - write stored fields to an invindex
=head1 DESCRIPTION
FieldsWriter writes fields which are marked as stored to the field data and
field index files.
=head1 COPYRIGHT
Copyright 2005-2010 Marvin Humphrey
=head1 LICENSE, DISCLAIMER, BUGS, etc.
See L<KinoSearch1> version 1.00.
=end devdocs
=cut
|