File Coverage

blib/lib/KinoSearch1/Search/Query.pm
Criterion Covered Total %
statement 25 31 80.6
branch 1 2 50.0
condition n/a
subroutine 8 14 57.1
pod 0 9 0.0
total 34 56 60.7


line stmt bran cond sub pod time code
1             package KinoSearch1::Search::Query;
2 18     18   114 use strict;
  18         40  
  18         552  
3 18     18   95 use warnings;
  18         71  
  18         389  
4 18     18   91 use KinoSearch1::Util::ToolSet;
  18         41  
  18         2463  
5 18     18   97 use base qw( KinoSearch1::Util::Class );
  18         31  
  18         3025  
6              
7             BEGIN {
8 18     18   149 __PACKAGE__->init_instance_vars(
9             # constructor params / members
10             boost => 1,
11             );
12 18         150 __PACKAGE__->ready_get_set(qw( boost ));
13             }
14              
15             =begin comment
16              
17             my $string = $query->to_string( $field_name );
18              
19             Return a string representation of the query. $field_name is a default field,
20             and affects how the string is generated -- for instance, if a TermQuery's
21             field matches $field_name, the field will be omitted, while if it doesn't
22             match, the field will be included in the string.
23              
24             =end comment
25             =cut
26              
27 0     0 0 0 sub to_string { shift->abstract_death }
28              
29             =begin comment
30              
31             my $weight = $query->create_weight($searcher);
32              
33             Only low-level Queries which rewrite themselves implement this method.
34              
35             =end comment
36             =cut
37              
38 0     0 0 0 sub create_weight { shift->abstract_death }
39              
40             # Derive a weight for a high-level query.
41             sub to_weight { # in Lucene, this method is simply "weight"
42 283     283 0 456 my ( $self, $searcher ) = @_;
43 283         1113 my $rewritten_self = $searcher->rewrite($self);
44 283         1328 my $weight = $rewritten_self->create_weight($searcher);
45 283         1282 my $sum = $weight->sum_of_squared_weights;
46 283         933 my $sim = $self->get_similarity($searcher);
47 283         1279 my $norm = $sim->query_norm($sum);
48 283         1447 $weight->normalize($norm);
49 283         1403 return $weight;
50             }
51              
52             =begin comment
53              
54             my $rewritten_query = $query->rewrite( $index_reader );
55              
56             Called by high-level Queries that wish to reformulate themselves as
57             agglomerations of low-level queries.
58              
59             =end comment
60             =cut
61              
62 279     279 0 744 sub rewrite { return shift }
63              
64             =begin comment
65              
66             my @terms = $query->extract_terms;
67              
68             Return all the Terms within this query.
69              
70             =end comment
71             =cut
72              
73 0     0 0 0 sub extract_terms { shift->abstract_death }
74              
75             # These will be needed by MultiSearcher if we add queries which rewrite
76             # themselves.
77 0     0 0 0 sub combine { shift->todo_death }
78 0     0 0 0 sub merge_boolean_queries { shift->todo_death }
79              
80             # return the Similarity implementation used by the Query.
81             sub get_similarity {
82 95     95 0 154 my ( $self, $searcher, $field_name ) = @_;
83             # This can be overriden in subclasses, allowing alternative Sims.
84 95 50       399 return defined $field_name
85             ? $searcher->get_similarity($field_name)
86             : $searcher->get_similarity;
87             }
88              
89 0     0 0   sub clone { shift->todo_death }
90              
91             1;
92              
93             __END__