blib/lib/KinoSearch1/Index/TermInfosReader.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 6 / 6 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 13 / 13 Podpod 20.0% 1 / 5 totaltotal 94.8% 74 / 78 CC 5 SCAR 4.6
CC
5
Cov
100%
_scan_enum
3.0
terms
2.0
fetch_term_info
2.0
CRAP 1.6
« blib/lib/KinoSearch1/Index/SegReader.pm ↑ Summary blib/lib/KinoSearch1/Search/Query.pm »
1 package KinoSearch1::Index::TermInfosReader;
2 34 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 34 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 34 ▶use KinoSearch1::Util::ToolSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 34 ▶use base qw( KinoSearch1::Util::Class );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 34 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 34 __PACKAGE__->init_instance_vars(
9 # constructor params / members
10 invindex => undef,
11 seg_name => undef,
12 finfos => undef,
13  
14 # members
15 orig_enum => undef,
16 index_enum => undef,
17 );
18 }
19  
20 34 ▶use KinoSearch1::Index::SegTermEnum;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 95 ▶sub init_instance {
Subroutine init_instance: called CC=1 SCAR=0.0
Pod documented
23 95 my $self = shift;
24 95 my $invindex = $self->{invindex};
25  
26 # prepare a main Enum which can access all terms
27 $self->{orig_enum} = KinoSearch1::Index::SegTermEnum->new(
28 finfos => $self->{finfos},
29 95 instream => $invindex->open_instream("$self->{seg_name}.tis"),
30 );
31  
32 # load an index Enum into memory which can point to places in main
33 $self->{index_enum} = KinoSearch1::Index::SegTermEnum->new(
34 finfos => $self->{finfos},
35 95 instream => $invindex->open_instream("$self->{seg_name}.tii"),
36 is_index => 1,
37 );
38 95 $self->{index_enum}->fill_cache;
39 }
40  
41 # Return a SegTermEnum, pre-located at the right spot if a Term is supplied.
42 17 ▶sub terms {
Subroutine terms: called CC=2 SCAR=6.9
Pod undocumented
43 17 my ( $self, $term ) = @_;
44 17 ▶ if ( defined $term ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $term) { } 1 16 17
45 1 $self->fetch_term_info($term);
46 }
47 else {
48 16 $self->{orig_enum}->reset;
49 }
50 17 return $self->{orig_enum}->clone_enum;
51 }
52  
53 # Given a Term, return a TermInfo if the Term is present in the segment, or
54 # undef if it's not.
55 2026 ▶sub fetch_term_info {
Subroutine fetch_term_info: called CC=2 SCAR=6.9
Pod undocumented
56 2026 my ( $self, $term ) = @_;
57 2026 my $termstring = $term->get_termstring( $self->{finfos} );
58  
59 # termstring will be undefined if field doesn't exist
60 2026 ▶ return unless defined $termstring;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $termstring 46 1980 2026
61  
62 1980 $self->_seek_enum($termstring);
63  
64 1980 return $self->_scan_enum($termstring);
65 }
66  
67 # Locate the main Enum as close as possible to where the term might be found.
68 1980 ▶sub _seek_enum {
Subroutine _seek_enum: called CC=1 SCAR=0.0
69 1980 my ( $self, $termstring ) = @_;
70 1980 my $index_enum = $self->{index_enum};
71  
72 # get the approximate possible location of the term in the main Enum
73 1980 my $tii_position = $index_enum->scan_cache($termstring);
74 1980 my $ballpark_termstring = $index_enum->get_termstring;
75 1980 my $ballpark_tinfo = $index_enum->get_term_info;
76  
77 # point the main Enum just before the term
78 $self->{orig_enum}->seek(
79 $ballpark_tinfo->get_index_fileptr,
80 1980 ( ( $tii_position * $self->{orig_enum}->get_index_interval ) - 1 ),
81 $ballpark_termstring,
82 $ballpark_tinfo,
83 );
84 }
85  
86 # One-by-one targeted iteration through TermEnum.
87 1980 ▶sub _scan_enum {
Subroutine _scan_enum: called CC=3 SCAR=11.0
88 1980 my ( $self, $target_termstring ) = @_;
89 1980 my $orig_enum = $self->{orig_enum};
90  
91 # iterate through the Enum until the result is ge the term
92 1980 $orig_enum->scan_to($target_termstring);
93  
94 # if the stopping point matches the target, return info; otherwise, undef
95 1980 my $found_termstring = $orig_enum->get_termstring;
96 1980 ▶ if ( defined $found_termstring
Branch: 1 branch
BranchTrueFalseTotal
if (defined $found_termstring and $found_termstring eq $target_termstring) 1786 194 1980
Condition100%3/3
defined $found_termstring and $found_termstring eq $target_termstring
!ll&&!rl&&r
401541786
MC/DC100%2/2
defined $found_termstring and $found_termstring eq $target_termstring
defined $found_termstring $found_termstring eq $target_termstring
Truth table100%3/3
A and B
A= defined $found_termstringB= $found_termstring eq $target_termstring
ABresult
0X0
100
111
97 and $found_termstring eq $target_termstring )
98 {
99 1786 return $orig_enum->get_term_info;
100 }
101 194 return;
102 }
103  
104 642 ▶sub get_skip_interval {
Subroutine get_skip_interval: called CC=1 SCAR=0.0
Pod undocumented
105 642 shift->{orig_enum}->get_skip_interval;
106 }
107  
108 39 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod undocumented
109 39 my $self = shift;
110 39 $self->{orig_enum}->close;
111 39 $self->{index_enum}->close;
112 }
113  
114 34 1;
115  
116 __END__
« blib/lib/KinoSearch1/Index/SegReader.pm ↑ Summary blib/lib/KinoSearch1/Search/Query.pm »