lib/KinoSearch1/Search/PhraseScorer.pm

filter: Statementstmt 100% 111 / 111 Branchbran 98.0% 49 / 50 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 99.3% 160 / 161 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« lib/KinoSearch1/Search/HitCollector.pm ↑ Summary blib/lib/KinoSearch1/Analysis/Analyzer.pm »
1 package KinoSearch1::Search::PhraseScorer;
2 use strict;
3 use warnings;
4 use KinoSearch1::Util::ToolSet;
5 use base qw( KinoSearch1::Search::Scorer );
6  
7 BEGIN {
8 __PACKAGE__->init_instance_vars(
9 # constructor params
10 weight => undef,
11 term_docs => undef,
12 phrase_offsets => undef,
13 norms_reader => undef,
14 slop => 0,
15 );
16 }
17 our %instance_vars;
18  
19 sub new {
20 my $either = shift;
21 confess kerror() unless verify_args( \%instance_vars, @_ );
22 my %args = ( %instance_vars, @_ );
23 my $self = $either->SUPER::new;
24 $self->_init_child;
25  
26 # set/derive some member vars
27 $self->_set_norms( $args{norms_reader}->get_bytes );
28 $self->set_similarity( $args{similarity} );
29 $self->_set_weight_value( $args{weight}->get_value );
30 confess("Sloppy phrase matching not yet implemented")
31 unless $args{slop} == 0; # TODO -- enable slop.
32 $self->_set_slop( $args{slop} );
33  
34 # sort terms by ascending frequency
35 confess("positions count doesn't match term count")
36 unless $#{ $args{term_docs} } == $#{ $args{phrase_offsets} };
37 my @by_size = sort { $a->[0]->get_doc_freq <=> $b->[0]->get_doc_freq }
38 map { [ $args{term_docs}[$_], $args{phrase_offsets}[$_] ] }
39 0 .. $#{ $args{term_docs} };
40 my @term_docs = map { $_->[0] } @by_size;
41 my @phrase_offsets = map { $_->[1] } @by_size;
42 $self->_init_elements( \@term_docs, \@phrase_offsets );
43  
44 return $self;
45 }
46  
47 1;
48  
49 __END__
« lib/KinoSearch1/Search/HitCollector.pm ↑ Summary blib/lib/KinoSearch1/Analysis/Analyzer.pm »