Plucene/Search/PrefixQuery.pm

filter: Statementstmt 100% 40 / 40 Branchbran 70.0% 7 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 90.5% 67 / 74 CC 8 SCAR 11.1
CC
8
Cov
91%
_query
6.1
to_string
3.1
BEGIN
1.0
CRAP 3.0
« Plucene/Search/IndexSearcher.pm ↑ Summary Plucene/Index/DocumentWriter.pm »
1 package Plucene::Search::PrefixQuery;
2  
3 =head1 NAME
4  
5 Plucene::Search::TermQuery - a query that matches terms beginning with a string
6  
7 =head1 SYNOPSIS
8  
9 # isa Plucene::Search::Query
10  
11 $prefix_query->normalize($norm);
12  
13 my $ssw = $prefix_query->sum_squared_weights($searcher);
14 my $as_string = $prefix_query->to_string($field);
15  
16 =head1 DESCRIPTION
17  
18 A query that matches a document containing terms I<beginning> with the
19 given string.
20  
21 =cut
22  
23 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use base 'Plucene::Search::Query';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use Plucene::Search::BooleanQuery;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Plucene::Search::TermQuery;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 2 __PACKAGE__->mk_accessors(qw/ prefix reader /);
30  
31 3 ▶sub prepare { $_[0]->reader($_[1]) }
Subroutine prepare: called CC=1 SCAR=0.0
Pod documented
32  
33 # This returns the underlying boolean query.
34  
35 9 ▶sub _query {
Subroutine _query: called CC=6 SCAR=18.0
36 9 my $self = shift;
37 9 ▶ return $self->{query} if exists $self->{query};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"query"} 6 3 9
38 3 my $q = new Plucene::Search::BooleanQuery;
39 3 my $prefix = $self->prefix;
40 3 my $enum = $self->reader->terms($prefix);
41 3 my ($field, $text) = ($prefix->field, $prefix->text);
42 3 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$enum->next and do { do { my $term = $enum->term; goto DONE unless $term and $term->text =~ /^\Q$text\E/ and $term->field eq $field; my $tq = "Plucene::Search::TermQuery"->new({"term", $term}); $tq->boost($self->boost); $q->add($tq, 0, 0) } } 9 0 9
43 12 my $term = $enum->term;
44 goto DONE
45 12 ▶ unless $term
Branch: 1 branch
BranchTrueFalseTotal
unless $term and $term->text =~ /^\Q$text\E/ and $term->field eq $field 3 9 12
Condition66%4/6
$term and $term->text =~ /^\Q$text\E/ and $term->field eq $field
!ll&&!rl&&r
309
$term and $term->text =~ /^\Q$text\E/
!ll&&!rl&&r
039
MC/DC33%1/3
$term and $term->text =~ /^\Q$text\E/ and $term->field eq $field
$term $term->text =~ /^\Q$text\E/ $term->field eq $field
Truth table50%2/4
A and B and C
A= $termB= $term->text =~ /^\Q$text\E/C= $term->field eq $field
ABCresult
0XX0
10X0
1100
1111
46 and $term->text =~ /^\Q$text/
47 and $term->field eq $field;
48 9 my $tq = Plucene::Search::TermQuery->new({ term => $term });
49 9 $tq->boost($self->boost);
50 9 $q->add($tq, 0, 0);
51 } while $enum->next;
52 3 DONE: $self->{query} = $q;
53 }
54  
55 =head2 to_string
56  
57 $q->to_string
58  
59 Convert the query to a readable string format
60  
61 =head2 sum_squared_weights
62  
63 The sum sqaured weights of the query.
64  
65 =head2 normalize
66  
67 Normalize the query.
68  
69 =cut
70  
71 1 ▶sub to_string {
Subroutine to_string: called CC=3 SCAR=11.2
Pod documented
72 1 my ($self, $field) = @_;
73 1 my $s = "";
74 1 ▶ $s = $self->prefix->field . ":" if $self->prefix->field ne $field;
Branch: 1 branch
BranchTrueFalseTotal
if $self->prefix->field ne $field 1 0 1
75 1 $s .= $self->prefix->text . "*";
76 1 ▶ $s .= "^" . $self->boost unless $self->boost == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->boost == 1 0 1 1
77 1 $s;
78 }
79  
80 3 ▶sub sum_squared_weights { shift->_query->sum_squared_weights(@_) }
Subroutine sum_squared_weights: called CC=1 SCAR=0.0
Pod documented
81 3 ▶sub normalize { shift->_query->normalize(@_) }
Subroutine normalize: called CC=1 SCAR=0.0
Pod documented
82 3 ▶sub _scorer { shift->_query->_scorer(@_) }
Subroutine _scorer: called CC=1 SCAR=0.0
83  
84 2 1;
« Plucene/Search/IndexSearcher.pm ↑ Summary Plucene/Index/DocumentWriter.pm »