line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
17
|
|
100
|
use strict; |
|
17
|
|
|
|
|
38
|
|
|
17
|
|
|
|
|
594
|
|
38
|
17
|
|
|
17
|
|
92
|
use warnings; |
|
17
|
|
|
|
|
40
|
|
|
17
|
|
|
|
|
565
|
|
39
|
|
|
|
|
|
|
|
40
|
17
|
|
|
17
|
|
97
|
use base qw/Class::Accessor::Fast/; |
|
17
|
|
|
|
|
37
|
|
|
17
|
|
|
|
|
5818
|
|
41
|
|
|
|
|
|
|
__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
|
|
|
|
|
|
|
sub new { |
55
|
277
|
|
|
277
|
1
|
15213
|
my ($self, $opts) = @_; |
56
|
277
|
50
|
|
|
|
1257
|
$opts->{boost} = 1 unless exists $opts->{boost}; |
57
|
277
|
|
|
|
|
1666
|
$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
|
|
|
|
|
|
|
sub scorer { |
68
|
179
|
|
|
179
|
1
|
536
|
my ($class, $query, $searcher, $reader) = @_; |
69
|
|
|
|
|
|
|
|
70
|
179
|
|
|
|
|
755
|
$query->prepare($reader); |
71
|
179
|
|
100
|
|
|
879
|
my $sum = $query->sum_squared_weights($searcher) || 1; |
72
|
179
|
|
|
|
|
566
|
my $norm = 1 / sqrt($sum); |
73
|
179
|
|
|
|
|
946
|
$query->normalize($norm); |
74
|
179
|
|
|
|
|
916
|
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
|
192
|
|
|
192
|
1
|
506
|
sub prepare { } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub sum_squared_weights { |
90
|
0
|
|
|
0
|
1
|
|
die "sum_squared_weights must be defined in a subclass"; |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
0
|
1
|
|
sub normalize { die "normalize must be defined in a subclass" } |
93
|
0
|
|
|
0
|
|
|
sub _scorer { die "_scorer must be defined in a subclass" } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |