Wiki/Indexer.pm

filter: Statementstmt 23.5% 12 / 51 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 3 / 7 Podpod 50.0% 2 / 4 totaltotal 22.3% 17 / 76 CC 8 SCAR 23.2
CC
8
Cov
19%
end_document
20.0
new
12.0
insert_word
6.0
CRAP 10.2
« Wiki.pm ↑ Summary
1 # $Id: Indexer.pm,v 1.2 2003/02/02 21:20:46 matt Exp $
2  
3 package AxKit::XSP::Wiki::Indexer;
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use XML::SAX::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 $VERSION = '1.00';
8 1 @ISA = qw(XML::SAX::Base);
9  
10 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
11 0 my $class = shift;
12 0 my (%opts) = @_;
13
14 0 ▶ my $db = $opts{DB} || die "DB argument required";
Condition0%0/2
$opts{'DB'} || die('DB argument required')
l!l
00
MC/DC0%0/1
$opts{'DB'} || die('DB argument required')
$opts{'DB'}
Truth table0%0/2
A
A= $opts{'DB'}
Aresult
11
00
15 0 ▶ my $page_id = $opts{PageId} || die "PageId argument required";
Condition0%0/2
$opts{'PageId'} || die('PageId argument required')
l!l
00
MC/DC0%0/1
$opts{'PageId'} || die('PageId argument required')
$opts{'PageId'}
Truth table0%0/2
A
A= $opts{'PageId'}
Aresult
11
00
16
17 0 my $self = bless { DB => $db, PageId => $page_id }, $class;
18
19 0 $self->{InsertCTI} = $db->prepare("INSERT INTO ContentIndex (page_id, word_id, value) VALUES (?, ?, ?)");
20 0 $self->{InsertWord} = $db->prepare("INSERT INTO Word (word) VALUES (?)");
21 0 $self->{InsertWord}->{PrintError} = 0;
22 0 $self->{FindWord} = $db->prepare("SELECT id FROM Word WHERE word = ?");
23 0 $self->{DeleteCTI} = $db->prepare("DELETE FROM ContentIndex WHERE page_id = ?");
24
25 0 $self->{Words} = {};
26 0 $self->{DocSize} = 0;
27
28 0 return $self;
29 }
30  
31 0 ▶sub end_document {
Subroutine end_document: not called CC=4 SCAR=30.0
Pod documented
32 0 my ($self) = @_;
33
34 # Delete current index for this page
35 0 $self->{DeleteCTI}->execute($self->{PageId});
36
37 0 for my $word (keys %{$self->{Words}}) {
38 0 ▶ next unless $word;
Branch: 1 branch
BranchTrueFalseTotal
unless $word 0 0 0
39 0 my $word_id = $self->insert_word($word);
40 0 ▶ next unless $word_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $word_id 0 0 0
41 0 warn("Indexing: $self->{PageId}, $word_id, $word\n");
42 $self->{InsertCTI}->execute(
43 $self->{PageId},
44 $word_id,
45 0 $self->{Words}{$word},
46 );
47 }
48 0 $self->{DB}->commit;
49 }
50  
51 0 ▶sub insert_word {
Subroutine insert_word: not called CC=2 SCAR=17.9
Pod undocumented
52 0 my ($self, $word) = @_;
53
54 0 my $word_id;
55 0 eval {
56 0 $self->{InsertWord}->execute($word);
57 0 $word_id = $self->{DB}->func('last_insert_rowid');
58 };
59 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
60 0 $self->{FindWord}->execute($word);
61 0 my $row = $self->{FindWord}->fetch;
62 0 $word_id = $row->[0];
63 }
64
65 0 return $word_id;
66 }
67  
68 # NB: This implementation assumes SAX parsers that don't break mid-word.
69 # (Could use filter if this is a problem)
70 0 ▶sub characters {
Subroutine characters: not called CC=2 SCAR=17.9
Pod documented
71 0 my ($self, $node) = @_;
72
73 0 ▶ while ($node->{Data} =~ /\G(\S*)\s*/gc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->{"Data"} =~ /\G(\S*)\s*/cg) 0 0 0
74 0 my $word = $1;
75 0 $word =~ s/\W*$//; # strip trailing non-word chars
76 0 $word =~ s/^\W*//; # strip leading non-word chars
77 0 $self->{Words}{lc($word)}++;
78 }
79 }
80  
81 1 1;
« Wiki.pm ↑ Summary