| 1 | package LucyX::Search::AnyTermCompiler; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use base qw( Lucy::Search::Compiler ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Lucy::Search::ORQuery; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Lucy::Search::TermQuery; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Data::Dump qw( dump ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '0.006'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | my $DEBUG = $ENV{LUCYX_DEBUG} || 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'LUCYX_DEBUG'} || 0
MC/DC0%0/1
$ENV{'LUCYX_DEBUG'} || 0
$ENV{'LUCYX_DEBUG'}
Truth table50%1/2
A
A= $ENV{'LUCYX_DEBUG'}
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # inside out vars | ||||||||||||||||||||||||||||
| 15 | 3 | my ( %searcher, %ORCompiler, %ORQuery, %subordinate ); | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | 6 | delete $ORQuery{$$self}; | |||||||||||||||||||||||||||
| 20 | 6 | delete $ORCompiler{$$self}; | |||||||||||||||||||||||||||
| 21 | 6 | delete $searcher{$$self}; | |||||||||||||||||||||||||||
| 22 | 6 | delete $subordinate{$$self}; | |||||||||||||||||||||||||||
| 23 | 6 | $self->SUPER::DESTROY; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =head1 NAME | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | LucyX::Search::AnyTermCompiler - Lucy query extension | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # see Lucy::Search::Compiler | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | =head1 METHODS | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | This class isa Lucy::Search::Compiler subclass. Only new | ||||||||||||||||||||||||||||
| 37 | or overridden methods are documented. | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =head2 new( I<args> ) | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | Returns a new Compiler object. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 6 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.5
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 6 | my $class = shift; | |||||||||||||||||||||||||||
| 49 | 6 | my %args = @_; | |||||||||||||||||||||||||||
| 50 | 6 | ▶ | my $searcher = $args{searcher} || $args{searchable}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{'searcher'} || $args{'searchable'}
MC/DC0%0/2
$args{'searcher'} || $args{'searchable'}
$args{'searcher'}
$args{'searchable'}
Truth table33%1/3
A || B
A= $args{'searcher'}B= $args{'searchable'}
| |||||||||||||||||||||||||||||
| 51 | 6 | ▶ | if ( !$searcher ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | croak "searcher required"; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 6 | my $subordinate = delete $args{subordinate}; | |||||||||||||||||||||||||||
| 56 | 6 | my $self = $class->SUPER::new(%args); | |||||||||||||||||||||||||||
| 57 | 6 | $searcher{$$self} = $searcher; | |||||||||||||||||||||||||||
| 58 | 6 | $subordinate{$$self} = $subordinate; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 6 | return $self; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head2 make_matcher( I<args> ) | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | Returns a Lucy::Search::ORMatcher object. | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | make_matcher() creates a Lucy::Search::ORQuery internally using all | ||||||||||||||||||||||||||||
| 68 | the terms associated with the parent AnyTermQuery field value, | ||||||||||||||||||||||||||||
| 69 | and returns the ORQuery's Matcher. | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 6 | ▶ | sub make_matcher { | ||||||||||||||||||||||||||
|
Subroutine
make_matcher: called CC=14 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 6 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 6 | my $parent = $self->get_parent; | |||||||||||||||||||||||||||
| 77 | 6 | my $field = $parent->get_field; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Retrieve low-level components | ||||||||||||||||||||||||||||
| 80 | 6 | ▶ | my $seg_reader = $args{reader} or croak "reader required"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 6 | my $lex_reader = $seg_reader->obtain("Lucy::Index::LexiconReader"); | |||||||||||||||||||||||||||
| 82 | 6 | my $lexicon = $lex_reader->lexicon( field => $field ); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 6 | ▶ | $DEBUG and warn "field:$field\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 6 | ▶ | if ( !$lexicon ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | #warn "no lexicon for field:$field"; | ||||||||||||||||||||||||||||
| 89 | 1 | return; | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # create ORQuery for all terms associated with $field | ||||||||||||||||||||||||||||
| 93 | 5 | my @terms; | |||||||||||||||||||||||||||
| 94 | 5 | ▶ | while ( defined( my $lex_term = $lexicon->get_term ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 50 | ▶ | $DEBUG and warn sprintf( "\n lex_term='%s'\n", | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 97 | ( defined $lex_term ? $lex_term : '[undef]' ), | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 50 | ▶ | if ( !defined $lex_term || !length $lex_term ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $lex_term and length $lex_term
MC/DC50%1/2
defined $lex_term and length $lex_term
defined $lex_term
length $lex_term
Truth table66%2/3
A and B
A= defined $lex_termB= length $lex_term
| |||||||||||||||||||||||||||||
| 101 | 5 | ▶ | last unless $lexicon->next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 5 | next; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 45 | push @terms, | |||||||||||||||||||||||||||
| 106 | Lucy::Search::TermQuery->new( | ||||||||||||||||||||||||||||
| 107 | term => $lex_term, | ||||||||||||||||||||||||||||
| 108 | field => $field, | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 45 | ▶ | last unless $lexicon->next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 5 | ▶ | return if !@terms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 5 | ▶ | $DEBUG and warn dump \@terms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 5 | my $or_query = Lucy::Search::ORQuery->new( children => \@terms, ); | |||||||||||||||||||||||||||
| 119 | 5 | $ORQuery{$$self} = $or_query; | |||||||||||||||||||||||||||
| 120 | my $or_compiler = $or_query->make_compiler( | ||||||||||||||||||||||||||||
| 121 | searcher => $searcher{$$self}, | ||||||||||||||||||||||||||||
| 122 | 5 | ▶ | boost => ( $args{boost} || 0 ), | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{'boost'} || 0
MC/DC0%0/1
$args{'boost'} || 0
$args{'boost'}
Truth table50%1/2
A
A= $args{'boost'}
| |||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||
| 124 | 5 | $ORCompiler{$$self} = $or_compiler; | |||||||||||||||||||||||||||
| 125 | 5 | return $or_compiler->make_matcher(%args); | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head2 get_child_compiler | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Returns the child ORCompiler, or undef if not defined. | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =cut | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub get_child_compiler { | ||||||||||||||||||||||||||
|
Subroutine
get_child_compiler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 136 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 137 | 0 | return $ORCompiler{$$self}; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | =head2 get_weight | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | Delegates to ORCompiler child. | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | sub get_weight { | ||||||||||||||||||||||||||
|
Subroutine
get_weight: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | return $self->get_child_compiler | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | ? $self->get_child_compiler->get_weight(@_) | ||||||||||||||||||||||||||||
| 150 | : $self->SUPER::get_weight(@_); | ||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head2 get_similarity | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | Delegates to ORCompiler child. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =cut | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub get_similarity { | ||||||||||||||||||||||||||
|
Subroutine
get_similarity: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 160 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 161 | 0 | ▶ | return $self->get_child_compiler | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | ? $self->get_child_compiler->get_similarity(@_) | ||||||||||||||||||||||||||||
| 163 | : $self->SUPER::get_similarity(@_); | ||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =head2 normalize | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | Delegates to ORCompiler child. | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =cut | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub normalize { | ||||||||||||||||||||||||||
|
Subroutine
normalize: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 173 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | return $self->get_child_compiler | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | ? $self->get_child_compiler->normalize(@_) | ||||||||||||||||||||||||||||
| 176 | : $self->SUPER::normalize(@_); | ||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head2 sum_of_squared_weights | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Delegates to ORCompiler child. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =cut | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub sum_of_squared_weights { | ||||||||||||||||||||||||||
|
Subroutine
sum_of_squared_weights: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 186 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 187 | 0 | ▶ | return $self->get_child_compiler | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | ? $self->get_child_compiler->sum_of_squared_weights(@_) | ||||||||||||||||||||||||||||
| 189 | : $self->SUPER::sum_of_squared_weights(@_); | ||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | =head2 highlight_spans | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | Delegates to ORCompiler child. | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | sub highlight_spans { | ||||||||||||||||||||||||||
|
Subroutine
highlight_spans: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 200 | 0 | ▶ | return $self->get_child_compiler | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | ? $self->get_child_compiler->highlight_spans(@_) | ||||||||||||||||||||||||||||
| 202 | : $self->SUPER::highlight_spans(@_); | ||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 3 | 1; | |||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | __END__ | ||||||||||||||||||||||||||||