Plucene/Search/Query.pm

filter: Statementstmt 86.9% 20 / 23 Branchbran 50.0% 1 / 2 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 66.6% 6 / 9 Podpod 100% 5 / 5 totaltotal 83.3% 35 / 42 CC 3 SCAR 5.0
CC
3
Cov
85%
new
2.0
scorer
2.0
sum_squared_weights
2.0
CRAP 1.6
« Plucene/Store/OutputStream.pm ↑ Summary Plucene/Store/InputStream.pm »
1 package Plucene::Search::Query;
2  
3 =head1 NAME
4  
5 Plucene::Search::Query - base class for queries
6  
7 =head1 SYNOPSIS
8  
9 my $s_query = Plucene::Search::Query::Subclass->new({
10 boost => $boost_factor});
11  
12 my $scorer = $s_query->scorer($query, $searcher, $reader);
13  
14 =head1 DESCRIPTION
15  
16 This is an abstract base class for queries.
17  
18 A query is a specification of the content an properties of the desired
19 documents. Every search is done by matching a query against the document
20 index and locating the ones that match the query.
21  
22 The simplest query specifies a single term (or word) that is to be matched
23 against a single field (e.g. 'author') of each of the documents in the index.
24 This kind of query matches any document that contains the term in the
25 specified field.
26  
27 A more complex queries may contain nested queries with 'and', 'or', 'not'
28 or 'phrase' relations. Queries may also contains specification of which
29 document fields to match against the various parts of the query
30 (.e.g. 'authors' and 'title') and hints that may effects the ranking of
31 the matched documents ('boost' factor).
32  
33 =head1 METHODS
34  
35 =cut
36  
37 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 17 ▶use base qw/Class::Accessor::Fast/;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 17 __PACKAGE__->mk_accessors(qw/boost/);
42  
43 =head2 new
44  
45 my $s_query = Plucene::Search::Query::Subclass->new({
46 boost => $boost_factor});
47  
48 =head2 boost
49  
50 Get / set this attribute
51  
52 =cut
53  
54 310 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
55 310 my ($self, $opts) = @_;
56 310 ▶ $opts->{boost} = 1 unless exists $opts->{boost};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"boost"} 310 0 310
57 310 $self->SUPER::new($opts);
58 }
59  
60 =head2 scorer
61  
62 my $scorer = $s_query->scorer
63 (Plucene::Search::Query $query, $searcher, $reader);
64  
65 =cut
66  
67 192 ▶sub scorer {
Subroutine scorer: called CC=2 SCAR=6.9
Pod documented
68 192 my ($class, $query, $searcher, $reader) = @_;
69  
70 192 $query->prepare($reader);
71 192 ▶ my $sum = $query->sum_squared_weights($searcher) || 1;
Condition100%2/2
$query->sum_squared_weights($searcher) || 1
l!l
1911
MC/DC100%1/1
$query->sum_squared_weights($searcher) || 1
$query->sum_squared_weights($searcher)
Truth table100%2/2
A
A= $query->sum_squared_weights($searcher)
Aresult
11
00
72 192 my $norm = 1 / sqrt($sum);
73 192 $query->normalize($norm);
74 192 return $query->_scorer($reader);
75 }
76  
77 =head2 prepare
78  
79 Does nothing
80  
81 =head2 sum_squared_weights / normalize / _scorer
82  
83 These must be defined in a subclass
84  
85 =cut
86  
87 209 ▶sub prepare { }
Subroutine prepare: called CC=1 SCAR=0.0
Pod documented
88  
89 0 ▶sub sum_squared_weights {
Subroutine sum_squared_weights: not called CC=1 SCAR=6.9
Pod documented
90 0 die "sum_squared_weights must be defined in a subclass";
91 }
92 0 ▶sub normalize { die "normalize must be defined in a subclass" }
Subroutine normalize: not called CC=1 SCAR=6.9
Pod documented
93 0 ▶sub _scorer { die "_scorer must be defined in a subclass" }
Subroutine _scorer: not called CC=1 SCAR=6.9
94  
95 17 1;
« Plucene/Store/OutputStream.pm ↑ Summary Plucene/Store/InputStream.pm »