MyConText/Column.pm

filter: Statementstmt 7.5% 5 / 66 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 14.2% 1 / 7 Podpod 0.0% 0 / 5 totaltotal 6.0% 6 / 100 CC 15 SCAR 33.0
CC
15
Cov
6%
add_document
42.0
_create_tables
30.0
contains_hashref
30.0
CRAP 27.1
« MyConText/String.pm ↑ Summary MyConText/URL.pm »
1  
2 package MyConText::Column;
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # Open in the backend just sets the object
6 0 ▶sub open {
Subroutine open: not called CC=1 SCAR=6.9
Pod undocumented
7 0 my ($class, $ctx) = @_;
8 0 return bless { 'ctx' => $ctx }, $class;
9 }
10 # Create creates the table(s) according to the parameters
11 0 ▶sub _create_tables {
Subroutine _create_tables: not called CC=5 SCAR=34.0
12 0 my ($class, $ctx) = @_;
13 0 my $COUNT_FIELD = '';
14 0 ▶ if ($ctx->{'count_bits'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"count_bits"}) 0 0 0
15 0 $COUNT_FIELD = "count $MyConText::BITS_TO_INT{$ctx->{'count_bits'}} unsigned,"
16 }
17 0 my $CREATE_DATA = <<EOF;
18 create table $ctx->{'data_table'} (
19 word_id $MyConText::BITS_TO_INT{$ctx->{'word_id_bits'}} unsigned not null,
20 doc_id $MyConText::BITS_TO_INT{$ctx->{'doc_id_bits'}} unsigned not null,
21 $COUNT_FIELD
22 index (word_id),
23 index (doc_id)
24 )
25 EOF
26  
27 $ctx->{'word_id_table'} = $ctx->{'table'}.'_words'
28 0 ▶ unless defined $ctx->{'word_id_table'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ctx->{"word_id_table"} 0 0 0
29
30
31 0 my $CREATE_WORD_ID = <<EOF;
32 create table $ctx->{'word_id_table'} (
33 word varchar($ctx->{'word_length'}) binary
34 default '' not null,
35 id $MyConText::BITS_TO_INT{$ctx->{'word_id_bits'}} unsigned not null auto_increment,
36 primary key (id),
37 unique (word)
38 )
39 EOF
40  
41 0 my $dbh = $ctx->{'dbh'};
42 0 ▶ $dbh->do($CREATE_DATA) or return $dbh->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do($CREATE_DATA) or return $dbh->errstr 0 0 0
43 0 push @{$ctx->{'created_tables'}}, $ctx->{'data_table'};
44 0 ▶ $dbh->do($CREATE_WORD_ID) or return $dbh->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do($CREATE_WORD_ID) or return $dbh->errstr 0 0 0
45 0 push @{$ctx->{'created_tables'}}, $ctx->{'word_id_table'};
46 0 return;
47 }
48 0 ▶sub add_document {
Subroutine add_document: not called CC=6 SCAR=37.4
Pod undocumented
49 0 my ($self, $id, $words) = @_;
50 0 my $ctx = $self->{'ctx'};
51 0 my $dbh = $ctx->{'dbh'};
52 0 my $data_table = $ctx->{'data_table'};
53 0 my $word_id_table = $ctx->{'word_id_table'};
54 0 ▶ if (not defined $self->{'insert_wordid_sth'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"insert_wordid_sth"}) 0 0 0
55 0 $self->{'insert_wordid_sth'} = $dbh->prepare("
56 insert into $word_id_table (word) values (?)
57 ");
58 0 $self->{'insert_wordid_sth'}->{'PrintError'} = 0;
59 0 $self->{'insert_wordid_sth'}->{'RaiseError'} = 0;
60 }
61 0 my $insert_wordid_sth = $self->{'insert_wordid_sth'};
62  
63 0 my $count_bits = $ctx->{'count_bits'};
64 my $insert_worddoc_sth = ( defined $self->{'insert_worddoc_sth'}
65 ? $self->{'insert_worddoc_sth'}
66 0 ▶ : $self->{'insert_worddoc_sth'} = (
Branch: 2 branches
BranchTrueFalseTotal
$count_bits ? : 0 0 0
defined $self->{'insert_worddoc_sth'} ? : 0 0 0
67 $count_bits
68 ? $dbh->prepare("
69 insert into $data_table
70 select id, ?, ? from $word_id_table
71 where word = ?")
72 : $dbh->prepare("
73 insert into $data_table
74 select id, ?, from $word_id_table
75 where word = ?")
76 ) );
77 0 my $num_words = 0;
78 0 for my $word ( keys %$words ) {
79 0 $insert_wordid_sth->execute($word);
80 0 ▶ if ($count_bits) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count_bits) { } 0 0 0
81 0 $insert_worddoc_sth->execute($id, $words->{$word}, $word);
82 }
83 else {
84 0 $insert_worddoc_sth->execute($id, $word);
85 }
86 0 $num_words += $words->{$word};
87 }
88 0 return $num_words;
89 }
90 0 ▶sub delete_document {
Subroutine delete_document: not called CC=2 SCAR=17.9
Pod undocumented
91 0 my $self = shift;
92 0 my $ctx = $self->{'ctx'};
93 0 my $dbh = $ctx->{'dbh'};
94 0 my $data_table = $ctx->{'data_table'};
95 0 my $sth = $dbh->prepare("delete from $data_table where doc_id = ?");
96 0 for my $id (@_) { $sth->execute($id); }
97 }
98 0 ▶sub update_document {
Subroutine update_document: not called CC=1 SCAR=6.9
Pod undocumented
99 0 my ($self, $id, $words) = @_;
100 0 $self->delete_document($id);
101 0 $self->add_document($id, $words);
102 }
103 0 ▶sub contains_hashref {
Subroutine contains_hashref: not called CC=5 SCAR=34.0
Pod undocumented
104 0 my $self = shift;
105 0 my $ctx = $self->{'ctx'};
106 0 my $dbh = $ctx->{'dbh'};
107 0 my $data_table = $ctx->{'data_table'};
108 0 my $word_id_table = $ctx->{'word_id_table'};
109  
110 0 my $count_bits = $ctx->{'count_bits'};
111 my $sth = ( defined $self->{'get_data_sth'}
112 ? $self->{'get_data_sth'}
113 : ( $count_bits
114 ? $self->{'get_data_sth'} = $dbh->prepare(
115 "select doc_id, count
116 from $data_table, $word_id_table
117 where word like ?
118 and id = word_id" )
119 0 ▶ : $self->{'get_data_sth'} = $dbh->prepare(
Branch: 2 branches
BranchTrueFalseTotal
defined $self->{'get_data_sth'} ? : 0 0 0
$count_bits ? : 0 0 0
120 "select doc_id, 1
121 from $data_table, $word_id_table
122 where word like ?
123 and id = word_id" )
124 ) );
125  
126 0 my $out = {};
127 0 for my $word (@_) {
128 0 $sth->execute($word);
129 0 ▶ while (my ($doc, $count) = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $sth->fetchrow_array) 0 0 0
130 0 $out->{$doc} += $count;
131 }
132 0 $sth->finish;
133 }
134 0 $out;
135 }
136  
137 1 *parse_and_index_data = \&MyConText::parse_and_index_data_count;
138  
139 1 1;
140  
« MyConText/String.pm ↑ Summary MyConText/URL.pm »