lib/KinoSearch1/Index/SegTermEnum.pm

filter: Statementstmt 96.2% 103 / 107 Branchbran 84.2% 32 / 38 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 93.1% 135 / 145 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/KinoSearch1/Store/OutStream.pm ↑ Summary lib/KinoSearch1/Search/Similarity.pm »
1 package KinoSearch1::Index::SegTermEnum;
2 use strict;
3 use warnings;
4 use KinoSearch1::Util::ToolSet;
5 use base qw( KinoSearch1::Util::Class );
6  
7 BEGIN {
8 __PACKAGE__->init_instance_vars(
9 # constructor params
10 finfos => undef,
11 instream => undef,
12 is_index => 0,
13 );
14 }
15 our %instance_vars;
16  
17 use KinoSearch1::Index::Term;
18 use KinoSearch1::Index::TermInfo;
19 use KinoSearch1::Index::TermBuffer;
20  
21 sub new {
22 # verify params
23 my $ignore = shift;
24 my %args = ( %instance_vars, @_ );
25 confess kerror() unless verify_args( \%instance_vars, %args );
26  
27 # get a TermBuffer helper object
28 my $term_buffer
29 = KinoSearch1::Index::TermBuffer->new( finfos => $args{finfos}, );
30  
31 return _new_helper( @args{ 'instream', 'is_index', 'finfos', },
32 $term_buffer );
33 }
34  
35 sub clone_enum {
36 my $self = shift;
37  
38 # dupe instream and seek it to the start of the file, so init works right
39 my $instream = $self->_get_instream;
40 my $new_stream = $instream->clone_stream;
41 $new_stream->seek(0);
42  
43 # create a new object and seek it to the right term/terminfo
44 my $evil_twin = __PACKAGE__->new(
45 finfos => $self->_get_finfos,
46 instream => $new_stream,
47 is_index => $self->is_index,
48 );
49 $evil_twin->seek(
50 $instream->tell, $self->_get_position,
51 $self->get_termstring, $self->get_term_info
52 );
53 return $evil_twin;
54 }
55  
56 # Locate the Enum to a particular spot.
57 sub seek {
58 my ( $self, $pointer, $position, $termstring, $tinfo ) = @_;
59  
60 # seek the filehandle
61 my $instream = $self->_get_instream;
62 $instream->seek($pointer);
63  
64 # set values as if we'd scanned here from the start of the Enum
65 $self->_set_position($position);
66 $self->_set_termstring($termstring);
67 $self->_set_term_info($tinfo);
68 }
69  
70 sub close {
71 my $instream = $_[0]->_get_instream;
72 $instream->close;
73 }
74  
75 # return a Term, if the Enum is currently valid.
76 sub get_term {
77 my $self = shift;
78 my $termstring = $self->get_termstring;
79 return unless defined $termstring;
80 return KinoSearch1::Index::Term->new_from_string( $termstring,
81 $self->_get_finfos );
82 }
83  
84 1;
85  
86 __END__
« lib/KinoSearch1/Store/OutStream.pm ↑ Summary lib/KinoSearch1/Search/Similarity.pm »