Perl Diver 2.33
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

Plucene::Index::TermInfosWriter

Name Plucene::Index::TermInfosWriter
Version
Located at /usr/share/perl5
File /usr/share/perl5/Plucene/Index/TermInfosWriter.pm
Is Core No
Search CPAN for this module Plucene::Index::TermInfosWriter
Documentation Plucene::Index::TermInfosWriter
Module Details Plucene::Index::TermInfosWriter

NAME

Plucene::Index::TermInfosWriter - write to the term infos file


SYNOPSIS

        my $writer = Plucene::Index::TermInfosWriter->new(
                $dir_name, $segment, $field_infos);
        $writer->add(Plucene::Index::Term $term, 
                        Plucene::Index::TermInfo $term_info);
        $writer->write_term(Plucene::Index::Term $term);


DESCRIPTION

This will allow for the writing and adding to a term infos file for a particular segment. It also writes the term infos index.


METHODS

new

        my $writer = Plucene::Index::TermInfosWriter->new(
                $dir_name, $segment, $field_infos);

This will create a new Plucene::Index::TermInfosWriter object.


=cut

sub new {
my ($class, $d, $segment, $fis, $is_i) = @_;

        my $self = bless {
                field_infos    => $fis,
                is_index       => $is_i,
                size           => 0,
                last_term      => Plucene::Index::Term->new({ field => "", text => "" }),
                last_ti        => Plucene::Index::TermInfo->new,
                last_index_ptr => 0,
                output         => Plucene::Store::OutputStream->new(
                        "$d/$segment.ti" . ($is_i ? "i" : "s")
                ),
        }, $class;
        confess("No field_infos!") unless $self->{field_infos};
        $self->{output}->write_int(0);    # Will be filled in when DESTROYed
        if (!$is_i) {
                $self->{other} = $class->new($d, $segment, $fis, 1);
                $self->{other}->{other} = $self;    # My enemy's enemy is my friend
        }
        return $self;
}

break_ref

This will break a circular reference.

add

        $writer->add(Plucene::Index::Term $term, 
                        Plucene::Index::TermInfo $term_info);

This will add the term and term info to the term infos file.


=cut

sub add {
my ($self, $term, $ti) = @_;
no warnings 'uninitialized';
carp sprintf ``Can't add out-of-order term %s lt %s (%s lt %s)'', $term->text,
$self->{last_term}->text, $term->field, $self->{last_term}->{field}
if !$self->{is_index} && $term->lt($self->{last_term});
carp ``Frequency pointer out of order''
if $ti->freq_pointer < $self->{last_ti}->freq_pointer;
carp ``Proximity pointer out of order''
if $ti->prox_pointer < $self->{last_ti}->prox_pointer;

        $self->{other}->add($self->{last_term}, $self->{last_ti})
                if !$self->{is_index}
                and (($self->{size} % INDEX_INTERVAL) == 0);
        $self->write_term($term);
        $self->{output}->write_vint($ti->doc_freq);
        $self->{output}
                ->write_vlong($ti->freq_pointer - $self->{last_ti}->freq_pointer);
        $self->{output}
                ->write_vlong($ti->prox_pointer - $self->{last_ti}->prox_pointer);
        if ($self->{is_index}) {    # I bet Tony will think about subclassing
                                          # at this point
                $self->{output}->write_vlong(
                        $self->{other}->{output}->tell - $self->{last_index_pointer});
                $self->{last_index_pointer} = $self->{other}->{output}->tell;
        }
        $self->{last_ti} = $ti->clone;
        $self->{size}++;
}

write_term

        $writer->write_term(Plucene::Index::Term $term);

This will write the term to the term infos file.


=cut

sub write_term {
my ($self, $term) = @_;
my $text = $term->text || ``'';
no warnings 'uninitialized';

        # Find longest common prefix
        ($text ^ $self->{last_term}->text) =~ /^(\0*)/;
        my $start = length $1;
        $self->{output}->write_vint($start);
        $self->{output}->write_string(substr($text, $start));
        $self->{output}
                ->write_vint($self->{field_infos}->field_number($term->field));
        $self->{last_term} = $term;
}

sub DESTROY { my $self = shift; $self->{output}->seek(0, 0); $self->{output}->write_int($self->{size}); }

1;

Perl Diver brought to you by ScriptSolutions.com © 1997- 2026