File Coverage

blib/lib/DBIx/TextIndex/TermDocsCache.pm
Criterion Covered Total %
statement 15 75 20.0
branch 0 18 0.0
condition 0 3 0.0
subroutine 5 19 26.3
pod 12 12 100.0
total 32 127 25.2


line stmt bran cond sub pod time code
1             package DBIx::TextIndex::TermDocsCache;
2              
3 8     8   51 use strict;
  8         15  
  8         323  
4 8     8   45 use warnings;
  8         15  
  8         484  
5              
6             our $VERSION = '0.26';
7              
8 8     8   49 use Bit::Vector;
  8         13  
  8         409  
9              
10 8     8   45 use base qw(DBIx::TextIndex);
  8         17  
  8         5361  
11              
12             sub new {
13 0     0 1   my $pkg = shift;
14 0   0       my $class = ref($pkg) || $pkg;
15 0           my $self = bless {}, $class;
16 0           my $args = shift;
17 0 0         $self->set($args) if $args;
18 0           return $self;
19             }
20              
21             sub max_indexed_id {
22 0     0 1   my $self = shift;
23 0 0         if (@_) {
24 0           $self->flush_all;
25 0           $self->{MAX_INDEXED_ID} = $_[0];
26             }
27 0           return $self->{MAX_INDEXED_ID};
28             }
29              
30             sub flush_all {
31 0     0 1   my $self = shift;
32 0           $self->flush_bit_vectors;
33 0           $self->flush_term_docs;
34             }
35              
36             sub flush_bit_vectors {
37 0     0 1   my $self = shift;
38 0           delete($self->{VECTOR});
39             }
40              
41             sub flush_term_docs {
42 0     0 1   my $self = shift;
43 0           delete($self->{TERM_DOCS});
44 0           delete($self->{DOCFREQ_T});
45             }
46              
47             sub term_pos {
48 0     0 1   my $self = shift;
49 0           my ($fno, $term) = @_;
50 0 0         $self->_fetch_term_pos($fno, $term) unless exists $self->{TERM_POS}->[$fno]->{$term};
51 0           return $self->{TERM_POS}->[$fno]->{$term};
52             }
53              
54             sub term_docs {
55 0     0 1   my $self = shift;
56 0           my ($fno, $term) = @_;
57 0 0         $self->_fetch_term_docs($fno, $term) unless exists $self->{TERM_DOCS}->[$fno]->{$term};
58 0           return $self->{TERM_DOCS}->[$fno]->{$term};
59             }
60              
61             sub term_docs_hashref {
62 0     0 1   my $self = shift;
63 0           my ($fno, $term) = @_;
64 0 0         $self->_fetch_term_docs($fno, $term) unless exists $self->{TERM_DOCS}->[$fno]->{$term};
65 0           return DBIx::TextIndex::term_docs_hashref($self->{TERM_DOCS}->[$fno]->{$term});
66              
67             }
68              
69             sub term_docs_arrayref {
70 0     0 1   my $self = shift;
71 0           my ($fno, $term) = @_;
72 0 0         $self->_fetch_term_docs($fno, $term) unless exists $self->{TERM_DOCS}->[$fno]->{$term};
73 0           return DBIx::TextIndex::term_docs_arrayref($self->{TERM_DOCS}->[$fno]->{$term});
74             }
75              
76             sub term_doc_ids_arrayref {
77 8     8   53 no warnings qw(uninitialized);
  8         13  
  8         4395  
78 0     0 1   my $self = shift;
79 0           my ($fno, $term) = @_;
80 0 0         $self->_fetch_term_docs($fno, $term) unless exists $self->{TERM_DOCS}->[$fno]->{$term};
81 0           return DBIx::TextIndex::term_doc_ids_arrayref($self->{TERM_DOCS}->[$fno]->{$term});
82             }
83              
84             sub vector {
85 0     0 1   my $self = shift;
86 0           my ($fno, $term) = @_;
87 0 0         if ($self->{VECTOR}->[$fno]->{$term}) {
88 0           return $self->{VECTOR}->[$fno]->{$term};
89             }
90 0           my $doc_ids = $self->term_doc_ids_arrayref($fno, $term);
91 0           my $vector = Bit::Vector->new($self->{MAX_INDEXED_ID} + 1);
92 0           $vector->Index_List_Store(@$doc_ids);
93 0           $self->{VECTOR}->[$fno]->{$term} = $vector;
94 0           return $vector;
95             }
96              
97             sub f_t {
98 0     0 1   my $self = shift;
99 0           my ($fno, $term) = @_;
100 0 0         $self->_fetch_term_docs($fno, $term)
101             unless exists $self->{DOCFREQ_T}->[$fno]->{$term};
102 0           return $self->{DOCFREQ_T}->[$fno]->{$term};
103             }
104              
105             sub _fetch_term_pos {
106 0     0     my $self = shift;
107 0           my ($fno, $term) = @_;
108 0           my $sql =
109             $self->{DB}->fetch_term_pos($self->{INVERTED_TABLES}->[$fno]);
110              
111 0           ($self->{TERM_POS}->[$fno]->{$term})
112             = $self->{INDEX_DBH}->selectrow_array($sql, undef, $term);
113             }
114              
115             sub _fetch_term_docs {
116 0     0     my $self = shift;
117 0           my ($fno, $term) = @_;
118 0           my $sql = $self->{DB}->fetch_term_freq_and_docs(
119             $self->{INVERTED_TABLES}->[$fno]);
120              
121 0           ($self->{DOCFREQ_T}->[$fno]->{$term}, $self->{TERM_DOCS}->[$fno]->{$term})
122             = $self->{INDEX_DBH}->selectrow_array($sql, undef, $term);
123             }
124              
125             __END__