| 1 | package Search::Query::Dialect::Lucy; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | extends 'Search::Query::Dialect::Native'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Data::Dump qw( dump ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 5 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Search::Query::Field::Lucy; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use Lucy::Search::ANDQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use Lucy::Search::NoMatchQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use Lucy::Search::NOTQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Lucy::Search::ORQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | use Lucy::Search::PhraseQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 5 | ▶ | use Lucy::Search::RangeQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 5 | ▶ | use Lucy::Search::TermQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | use LucyX::Search::ProximityQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | use LucyX::Search::NOTWildcardQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | use LucyX::Search::WildcardQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | use LucyX::Search::NullTermQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use LucyX::Search::AnyTermQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | our $VERSION = '0.202'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 207 | ▶ | has 'wildcard' => ( is => 'rw', default => sub {'*'} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 199 | ▶ | has 'fuzzify' => ( is => 'rw', default => sub {0} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 207 | ▶ | has 'ignore_order_in_proximity' => ( is => 'rw', default => sub {0} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 207 | ▶ | has 'allow_single_wildcards' => ( is => 'rw', default => sub {0} ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | Search::Query::Dialect::Lucy - Lucy query dialect | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | use Lucy; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | use Search::Query; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | my ($idx, $query) = get_index_name_and_query(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | my $searcher = Lucy::Search::IndexSearcher->new( index => $idx ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | my $schema = $searcher->get_schema(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # build field mapping | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | my %fields; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | for my $field_name ( @{ $schema->all_fields() } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | $fields{$field_name} = { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | type => $schema->fetch_type($field_name), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | analyzer => $schema->fetch_analyzer($field_name), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | my $query_parser = Search::Query->parser( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | dialect => 'Lucy', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | croak_on_error => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | default_field => 'foo', # applied to "bare" terms with no field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | fields => \%fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | my $parsed_query = $query_parser->parse($query); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | my $lucy_query = $parsed_query->as_lucy_query(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | my $hits = $searcher->hits( query => $lucy_query ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | Search::Query::Dialect::Lucy extends the Lucy::QueryParser syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | to support wildcards, proximity and ranges, in addition to the standard | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | Search::Query features. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | This class is a subclass of Search::Query::Dialect. Only new or overridden | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | methods are documented here. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | =head2 BUILD | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Sets Lucy-appropriate defaults. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | Can take the following params, also available as standard attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | =item wildcard | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | Default is '*'. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | =item allow_single_wildcards | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | If true, terms like '*' and '?' are allowed as valid. If false, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | the Parser will croak if any term consists solely of a wildcard. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | The default is false. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | =item fuzzify | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | If true, a wildcard is automatically appended to each query term. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | =item ignore_order_in_proximity | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | If true, the terms in a proximity query will be evaluated for | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | matches regardless of the order in which they appear. For example, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | given a document excerpt like: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | foo bar bing | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | and a query like: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | "bing foo"~5 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | if ignore_order_in_proximity is true, the document would match. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | If ignore_order_in_proximity is false (the default), the document would | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | not match. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 207 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 207 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 207 | ▶ | if ( $self->{default_field} and !ref( $self->{default_field} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"default_field"} and not ref $self->{"default_field"}
MC/DC100%2/2
$self->{"default_field"} and not ref $self->{"default_field"}
$self->{"default_field"}
not ref $self->{"default_field"}
Truth table100%3/3
A and not(B)
A= $self->{"default_field"}B= not ref $self->{"default_field"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | $self->{default_field} = [ $self->{default_field} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 207 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | =head2 stringify | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | Returns the Query object as a normalized string. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | my %op_map = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | '+' => ' AND ', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | '' => ' OR ', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | '-' => ' ', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 178 | ▶ | sub _get_clause_joiner { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_clause_joiner: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 178 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 178 | ▶ | if ( $self->parser->default_boolop eq '+' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 174 | return 'AND'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | return 'OR'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 119 | ▶ | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 119 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 119 | ▶ | my $tree = shift || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self
MC/DC0%0/2
shift() || $self
shift()
$self
Truth table66%2/3
A || B
A= shift()B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 119 | my @q; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 119 | foreach my $prefix ( '+', '', '-' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 355 | my @clauses; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 355 | my $joiner = $op_map{$prefix}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 355 | ▶ | next unless exists $tree->{$prefix}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 123 | for my $clause ( @{ $tree->{$prefix} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 163 | push( @clauses, $self->stringify_clause( $clause, $prefix ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 122 | ▶ | next if !@clauses; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 122 | ▶ | push @q, join( $joiner, grep { defined and length } @clauses ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 118 | my $clause_joiner = $self->_get_clause_joiner; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 118 | return join " $clause_joiner ", @q; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 178 | ▶ | sub _doctor_value { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_doctor_value: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 178 | my ( $self, $clause ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 178 | my $value = $clause->{value}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 178 | ▶ | if ( defined $value and $self->fuzzify ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and $self->fuzzify
MC/DC100%2/2
defined $value and $self->fuzzify
defined $value
$self->fuzzify
Truth table100%3/3
A and B
A= defined $valueB= $self->fuzzify
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 8 | ▶ | $value .= '*' unless $value =~ m/[\*]/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 178 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | =head2 stringify_clause( I<leaf>, I<prefix> ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | Called by stringify() to handle each Clause in the Query tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 163 | ▶ | sub stringify_clause { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify_clause: called CC=48 SCAR=39.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 163 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 163 | my $clause = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 163 | my $prefix = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | #warn '=' x 80; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | #warn dump $clause; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | #warn "prefix = '$prefix'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 163 | ▶ | if ( $clause->{op} eq '()' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 33 | my $str = $self->stringify( $clause->{value} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 33 | ▶ | if ( $clause->has_children and $clause->has_children == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$clause->has_children and $clause->has_children == 1
MC/DC50%1/2
$clause->has_children and $clause->has_children == 1
$clause->has_children
$clause->has_children == 1
Truth table66%2/3
A and B
A= $clause->has_childrenB= $clause->has_children == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 17 | ▶ | if ( $prefix eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | return "(NOT ($str))"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # try not to double up the () unnecessarily | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 16 | ▶ | if ( $str =~ m/^\(/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 4 | return $str; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 12 | return "($str)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 16 | ▶ | if ( $prefix eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | ▶ | if ( $str =~ m/^\(/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | return "(NOT $str)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | return "(NOT ($str))"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 14 | return "($str)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 130 | ▶ | my $quote = $clause->quote || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$clause->quote || ''
MC/DC100%1/1
$clause->quote || ''
$clause->quote
Truth table100%2/2
A
A= $clause->quote
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 130 | ▶ | my $proximity = $clause->proximity || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$clause->proximity || ''
MC/DC100%1/1
$clause->proximity || ''
$clause->proximity
Truth table100%2/2
A
A= $clause->proximity
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 130 | ▶ | if ($proximity) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | $proximity = '~' . $proximity; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # make sure we have a field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 130 | ▶ | my $default_field | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%5/5
$self->default_field || $self->parser->default_field || undef
$self->default_field or $self->parser->default_field
MC/DC100%2/2
$self->default_field || $self->parser->default_field || undef
$self->default_field
$self->parser->default_field
Truth table100%3/3
A or B
A= $self->default_fieldB= $self->parser->default_field
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | = $self->default_field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | || $self->parser->default_field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | || undef; # not empty string or 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 130 | my @fields; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 130 | ▶ | if ( $clause->{field} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 96 | @fields = ( $clause->{field} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | elsif ( defined $default_field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 20 | ▶ | if ( ref $default_field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 20 | @fields = @$default_field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | @fields = ($default_field); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # what value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | my $value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | = ref $clause->{value} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | ? $clause->{value} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 130 | ▶ | : $self->_doctor_value($clause); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # if we have no fields, then operator is ignored. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 130 | ▶ | if ( !@fields ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 14 | ▶ | $self->debug and warn "no fields for " . dump($clause); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 14 | my $str = qq/$quote$value$quote$proximity/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 14 | ▶ | return $prefix eq '-' ? ( 'NOT ' . $str ) : $str; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 116 | my $wildcard = $self->wildcard; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # normalize operator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 116 | ▶ | my $op = $clause->{op} || ":"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$clause->{'op'} || ':'
MC/DC100%1/1
$clause->{'op'} || ':'
$clause->{'op'}
Truth table100%2/2
A
A= $clause->{'op'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 116 | $op =~ s/=/:/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 116 | ▶ | if ( $prefix eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 22 | ▶ | $op = '!' . $op unless $op =~ m/^!/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 116 | ▶ | if ( defined $value and $value =~ m/[\*\?]|\Q$wildcard/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and $value =~ /[\*\?]|\Q$wildcard\E/
MC/DC100%2/2
defined $value and $value =~ /[\*\?]|\Q$wildcard\E/
defined $value
$value =~ /[\*\?]|\Q$wildcard\E/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /[\*\?]|\Q$wildcard\E/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 23 | $op =~ s/:/~/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 23 | ▶ | if ( $value eq '*' or $value eq '?' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$value eq "*" or $value eq "?"
MC/DC50%1/2
$value eq "*" or $value eq "?"
$value eq "*"
$value eq "?"
Truth table66%2/3
A or B
A= $value eq "*"B= $value eq "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 1 | ▶ | if ( !$self->allow_single_wildcards ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 1 | croak "single wildcards are not allowed: $clause"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 115 | my @buf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 115 | NAME: for my $name (@fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 160 | my $field = $self->get_field($name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 160 | ▶ | if ( defined $field->callback ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | push( @buf, $field->callback->( $field, $op, $value ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | next NAME; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 160 | ▶ | ( $self->debug > 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | and warn "lucy string: " | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | . dump [ $name, $op, $prefix, $quote, $value, ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 160 | ▶ | if ( !defined $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 4 | $value = 'NULL'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | # invert fuzzy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 160 | ▶ | if ( $op eq '!~' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 2 | ▶ | $value .= $wildcard unless $value =~ m/\Q$wildcard/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | join( '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | '(NOT ', $name, ':', qq/$quote$value$quote$proximity/, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | ')' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # fuzzy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | elsif ( $op eq '~' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 35 | ▶ | $value .= $wildcard unless $value =~ m/\Q$wildcard/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 35 | push( @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | join( '', $name, ':', qq/$quote$value$quote$proximity/ ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | # invert | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | elsif ( $op eq '!:' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # double negative | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 34 | ▶ | if ( $prefix eq '-' and $clause->{op} eq '!:' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prefix eq "-" and $clause->{"op"} eq "!:"
MC/DC100%2/2
$prefix eq "-" and $clause->{"op"} eq "!:"
$prefix eq "-"
$clause->{"op"} eq "!:"
Truth table100%3/3
A and B
A= $prefix eq "-"B= $clause->{"op"} eq "!:"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | push @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | join( '', $name, ':', qq/$quote$value$quote$proximity/ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 33 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | join( '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | '(NOT ', $name, ':', qq/$quote$value$quote$proximity/, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | ')' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # range | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | elsif ( $op eq '..' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 5 | ▶ | if ( ref $value ne 'ARRAY' or @$value != 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value ne "ARRAY" or @$value != 2
MC/DC0%0/2
ref $value ne "ARRAY" or @$value != 2
ref $value ne "ARRAY"
@$value != 2
Truth table33%1/3
A or B
A= ref $value ne "ARRAY"B= @$value != 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | croak "range of values must be a 2-element ARRAY"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | push( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 5 | @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | join( '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | $name, ':', '(', $value->[0], '..', $value->[1], ')' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | # invert range | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | elsif ( $op eq '!..' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 6 | ▶ | if ( ref $value ne 'ARRAY' or @$value != 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value ne "ARRAY" or @$value != 2
MC/DC0%0/2
ref $value ne "ARRAY" or @$value != 2
ref $value ne "ARRAY"
@$value != 2
Truth table33%1/3
A or B
A= ref $value ne "ARRAY"B= @$value != 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | croak "range of values must be a 2-element ARRAY"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | push( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 6 | @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | join( '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | $name, '!:', '(', $value->[0], '..', $value->[1], ')' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # standard | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 78 | push( @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | join( '', $name, ':', qq/$quote$value$quote$proximity/ ) ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 115 | ▶ | my $joiner = $prefix eq '-' ? ' AND ' : ' OR '; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 115 | ▶ | ( scalar(@buf) > 1 ? '(' : '' ) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | . join( $joiner, @buf ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | . ( scalar(@buf) > 1 ? ')' : '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | =head2 as_lucy_query | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | Returns the Dialect object as a Lucy::Search::Query-based object. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | The Dialect object is walked and converted to a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | Lucy::Searcher-compatible tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 5 | my %lucy_class_map = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | '+' => 'AND', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | '' => 'OR', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | '-' => 'NOT', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 60 | ▶ | sub as_lucy_query { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_lucy_query: called CC=19 SCAR=29.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 60 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 60 | ▶ | my $tree = shift || $self; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() || $self
MC/DC0%0/2
shift() || $self
shift()
$self
Truth table66%2/3
A || B
A= shift()B= $self
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 60 | my @q; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 60 | foreach my $prefix ( '+', '', '-' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 180 | my @clauses; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 180 | my $joiner = $lucy_class_map{$prefix}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 180 | ▶ | next unless exists $tree->{$prefix}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 62 | my $has_explicit_fields = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 62 | for my $clause ( @{ $tree->{$prefix} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 84 | my @lucy_clauses = $self->_lucy_clause( $clause, $prefix ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 84 | ▶ | if ( !@lucy_clauses ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | #warn "No lucy_clauses for $clause"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 84 | push( @clauses, @lucy_clauses ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 84 | ▶ | if ( defined $clause->{field} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 68 | $has_explicit_fields++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 62 | ▶ | next if !@clauses; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 62 | my $lucy_class = 'Lucy::Search::' . $joiner . 'Query'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 62 | ▶ | my $lucy_param_name = $joiner eq 'NOT' ? 'negated_query' : 'children'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 62 | @clauses = grep {defined} @clauses; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 62 | ▶ | if ( $prefix eq '-' and @clauses > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$prefix eq "-" and @clauses > 1
MC/DC100%2/2
$prefix eq "-" and @clauses > 1
$prefix eq "-"
@clauses > 1
Truth table100%3/3
A and B
A= $prefix eq "-"B= @clauses > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | $lucy_class = 'Lucy::Search::ANDQuery'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | $lucy_param_name = 'children'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | #warn "$lucy_class -> new( $lucy_param_name => " . dump \@clauses; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | #warn "has_explicit_fields=$has_explicit_fields"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 62 | ▶ | if ( @clauses == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 48 | ▶ | if ( $prefix eq '-' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$prefix eq "-" and $has_explicit_fields and not $clauses[0]->isa($lucy_class)
$prefix eq "-" and $has_explicit_fields
MC/DC100%3/3
$prefix eq "-" and $has_explicit_fields and not $clauses[0]->isa($lucy_class)
$prefix eq "-"
$has_explicit_fields
not $clauses[0]->isa($lucy_class)
Truth table100%4/4
A and B and not(C)
A= $prefix eq "-"B= $has_explicit_fieldsC= not $clauses[0]->isa($lucy_class)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | and $has_explicit_fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | and !$clauses[0]->isa($lucy_class) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 1 | push @q, $lucy_class->new( $lucy_param_name => $clauses[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 47 | push @q, $clauses[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | ▶ | elsif ( !$has_explicit_fields and $prefix eq '-' ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $has_explicit_fields and $prefix eq "-"
MC/DC0%0/2
not $has_explicit_fields and $prefix eq "-"
not $has_explicit_fields
$prefix eq "-"
Truth table66%2/3
not(A) and B
A= not $has_explicit_fieldsB= $prefix eq "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | warn "do not wrap \@clauses in a $lucy_class"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | push @q, @clauses; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 14 | push @q, $lucy_class->new( $lucy_param_name => \@clauses ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # possible we end up with nothing if StopFilter applied | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 60 | ▶ | if ( !@q ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 60 | my $clause_joiner = $self->_get_clause_joiner; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 60 | my $lucy_class_joiner = 'Lucy::Search::' . $clause_joiner . 'Query'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 60 | ▶ | return @q == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | ? $q[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | : $lucy_class_joiner->new( children => \@q ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 84 | ▶ | sub _lucy_clause { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lucy_clause: called CC=67 SCAR=46.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 84 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 84 | my $clause = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 84 | my $prefix = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | #warn dump $clause; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | #warn "prefix = '$prefix'"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 84 | ▶ | if ( $clause->{op} eq '()' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 18 | return $self->as_lucy_query( $clause->{value} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # make sure we have a field | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 66 | ▶ | my $default_field = $self->default_field || $self->parser->default_field; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->default_field || $self->parser->default_field
MC/DC100%2/2
$self->default_field || $self->parser->default_field
$self->default_field
$self->parser->default_field
Truth table100%3/3
A || B
A= $self->default_fieldB= $self->parser->default_field
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 66 | my @fields; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 66 | ▶ | if ( $clause->{field} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 50 | @fields = ( $clause->{field} ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | elsif ( defined $default_field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 16 | ▶ | if ( ref $default_field ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 16 | @fields = @$default_field; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | @fields = ($default_field); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # what value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | my $value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | = ref $clause->{value} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | ? $clause->{value} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 66 | ▶ | : $self->_doctor_value($clause); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # if we have no fields, we can't proceed, because Lucy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # requires a field for every term. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 66 | ▶ | if ( !@fields ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | croak | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | "No field specified for term '$value' -- set a default_field in Parser or Dialect"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 66 | my $wildcard = $self->wildcard; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # normalize operator | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 66 | ▶ | my $op = $clause->{op} || ":"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$clause->{'op'} || ':'
MC/DC100%1/1
$clause->{'op'} || ':'
$clause->{'op'}
Truth table100%2/2
A
A= $clause->{'op'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 66 | $op =~ s/=/:/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 66 | ▶ | if ( $prefix eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 14 | ▶ | $op = '!' . $op unless $op =~ m/^!/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 66 | ▶ | if ( defined $value and $value =~ m/[\*\?]|\Q$wildcard/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and $value =~ /[\*\?]|\Q$wildcard\E/
MC/DC100%2/2
defined $value and $value =~ /[\*\?]|\Q$wildcard\E/
defined $value
$value =~ /[\*\?]|\Q$wildcard\E/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /[\*\?]|\Q$wildcard\E/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 13 | $op =~ s/:/~/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 13 | ▶ | if ( $value eq '*' or $value eq '?' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$value eq "*" or $value eq "?"
MC/DC0%0/2
$value eq "*" or $value eq "?"
$value eq "*"
$value eq "?"
Truth table33%1/3
A or B
A= $value eq "*"B= $value eq "?"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | if ( !$self->allow_single_wildcards ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | croak "single wildcards are not allowed: $clause"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 66 | ▶ | my $quote = $clause->quote || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$clause->quote || ''
MC/DC100%1/1
$clause->quote || ''
$clause->quote
Truth table100%2/2
A
A= $clause->quote
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 66 | ▶ | my $is_phrase = $quote eq '"' ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 66 | ▶ | my $proximity = $clause->proximity || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$clause->proximity || ''
MC/DC100%1/1
$clause->proximity || ''
$clause->proximity
Truth table100%2/2
A
A= $clause->proximity
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 66 | my @buf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 66 | FIELD: for my $name (@fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 108 | my $field = $self->get_field($name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 108 | ▶ | if ( defined $field->callback ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | push( @buf, $field->callback->( $field, $op, $value ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | next FIELD; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 108 | ▶ | if ( $self->debug ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | warn "as_lucy_query:\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | warn dump( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | { name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | op => $op, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | prefix => $prefix, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | quote => $quote, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | value => $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | clause_op => $clause->{op}, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ) . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 108 | ▶ | if ( !defined $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 4 | ▶ | if ( $op eq '!:' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 3 | ▶ | if ( $prefix eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | # original op was inverted above by $prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 2 | ▶ | if ( $clause->{op} eq ':' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | # appears to be a double negative, but necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # to get the logic and serialization correct. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | # e.g. NOT foo:NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | push @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | Lucy::Search::NOTQuery->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | negated_query => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | $field->nullterm_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | field => $name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | # true double negative | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | # e.g. NOT foo!:NULL => foo:NULL | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 1 | push @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | $field->nullterm_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | field => $name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 1 | push @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | $field->anyterm_query_class->new( field => $name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 1 | push @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | $field->nullterm_query_class->new( field => $name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 4 | next FIELD; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | # range is un-analyzed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 104 | ▶ | if ( $op eq '..' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 3 | ▶ | if ( ref $value ne 'ARRAY' or @$value != 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value ne "ARRAY" or @$value != 2
MC/DC0%0/2
ref $value ne "ARRAY" or @$value != 2
ref $value ne "ARRAY"
@$value != 2
Truth table33%1/3
A or B
A= ref $value ne "ARRAY"B= @$value != 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | croak "range of values must be a 2-element ARRAY"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 3 | my $range_query = $field->range_query_class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | lower_term => $value->[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | upper_term => $value->[1], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | include_lower => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | include_upper => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 3 | push( @buf, $range_query ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 3 | next FIELD; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | # invert range | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | elsif ( $op eq '!..' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 4 | ▶ | if ( ref $value ne 'ARRAY' or @$value != 2 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $value ne "ARRAY" or @$value != 2
MC/DC0%0/2
ref $value ne "ARRAY" or @$value != 2
ref $value ne "ARRAY"
@$value != 2
Truth table33%1/3
A or B
A= ref $value ne "ARRAY"B= @$value != 2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | croak "range of values must be a 2-element ARRAY"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 4 | my $range_query = $field->range_query_class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | lower_term => $value->[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | upper_term => $value->[1], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | include_lower => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | include_upper => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 4 | push( @buf, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | Lucy::Search::NOTQuery->new( negated_query => $range_query ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 4 | next FIELD; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | #$self->debug and warn "value before:$value"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 97 | my @values = ($value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | # if the field has an analyzer, use it on $value | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 97 | ▶ | if ( blessed( $field->analyzer ) && !ref $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
builtin::blessed($field->analyzer) and not ref $value
MC/DC50%1/2
builtin::blessed($field->analyzer) and not ref $value
builtin::blessed($field->analyzer)
not ref $value
Truth table66%2/3
A and not(B)
A= builtin::blessed($field->analyzer)B= not ref $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # preserve any wildcards | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 92 | ▶ | if ( $value =~ m/[$wildcard\*\?]/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | # can't use full PolyAnalyzer since it will tokenize | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # and strip the wildcards off. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | # assume CaseFolder | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | # TODO do not assume | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 27 | $value = lc($value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | # split on whitespace, not token regex | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 27 | my @tok = split( m/\s+/, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | # if stemmer, apply only to prefix if at all. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 27 | my $stemmer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 27 | ▶ | if ( $field->analyzer->isa('Lucy::Analysis::PolyAnalyzer') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 27 | my $analyzers = $field->analyzer->get_analyzers(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 27 | for my $ana (@$analyzers) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 81 | ▶ | if ( $ana->isa('Lucy::Analysis::SnowballStemmer') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 27 | $stemmer = $ana; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 27 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | elsif ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | $field->analyzer->isa('Lucy::Analysis::SnowballStemmer') ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | $stemmer = $field->analyzer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 27 | ▶ | if ($stemmer) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 27 | for my $tok (@tok) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 27 | ▶ | if ( $tok =~ s/^(\w+)\*$/$1/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 18 | my $stemmed = $stemmer->split($tok); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | # re-append the wildcard | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | # TODO ever have multiple? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 18 | $tok = $stemmed->[0] . '*'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 27 | @values = @tok; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 78 | ▶ | @values = grep { defined and length } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 65 | @{ $field->analyzer->split($value) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | # if we have a StopFilter in our analyzer chain, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | # it's possible the @values ends up empty. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | # The Lucy QueryParser will handle that case | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # by trying twice with a NoMatchQuery. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | # TODO what should our behavior be? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | # a stopword will never match since the word | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | # won't be in the index... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | #$self->debug and warn "value after :" . dump( \@values ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | # StopFilter or similar case | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 97 | ▶ | if ( !@values ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 97 | ▶ | if ( $is_phrase or @values > 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_phrase or @values > 1
MC/DC50%1/2
$is_phrase or @values > 1
$is_phrase
@values > 1
Truth table66%2/3
A or B
A= $is_phraseB= @values > 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 16 | ▶ | if ($proximity) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 12 | ▶ | if ( $self->ignore_order_in_proximity ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 4 | my $n_values = scalar @values; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 4 | my @permutations; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 4 | ▶ | while ( $n_values-- > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 8 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | @permutations, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | $field->proximity_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | terms => [@values], # new array | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | within => $proximity, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 8 | push( @values, shift(@values) ); # shuffle | |||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | $self->debug | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | ▶ | and dump [ map { $_->get_terms } @permutations ]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 4 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | Lucy::Search::ORQuery->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | children => \@permutations, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 8 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | $field->proximity_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | terms => \@values, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | within => $proximity, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # invert | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 4 | ▶ | if ( $op eq '!:' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 2 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | Lucy::Search::NOTQuery->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | negated_query => $field->phrase_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | terms => \@values, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | # standard | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 2 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | $field->phrase_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | terms => \@values, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 81 | my $term = $values[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | # TODO why would this happen? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 81 | ▶ | if ( !defined $term or !length $term ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $term and length $term
MC/DC0%0/2
defined $term and length $term
defined $term
length $term
Truth table33%1/3
A and B
A= defined $termB= length $term
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | warn "No term defined"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | next FIELD; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | # invert fuzzy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 81 | ▶ | if ( $op eq '!~' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%4/6
$op eq "!~" or $op eq "!:" and $term =~ /[$wildcard\*\?]/
$op eq "!:" and $term =~ /[$wildcard\*\?]/
MC/DC33%1/3
$op eq "!~" or $op eq "!:" and $term =~ /[$wildcard\*\?]/
$op eq "!~"
$op eq "!:"
$term =~ /[$wildcard\*\?]/
Truth table75%3/4
A or B and C
A= $op eq "!~"B= $op eq "!:"C= $term =~ /[$wildcard\*\?]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | || ( $op eq '!:' and $term =~ m/[$wildcard\*\?]/ ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 2 | ▶ | $term .= $wildcard unless $term =~ m/\Q$wildcard/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | # if the prefix is already NOT do not apply a double negative | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 2 | ▶ | if ( $prefix eq '-' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 1 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | $field->wildcard_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | term => $term, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | elsif ( $op =~ m/^\!/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 1 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | Lucy::Search::NOTQuery->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | negated_query => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | $field->wildcard_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | term => $term, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | $field->wildcard_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | term => $term, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | # fuzzy | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | ▶ | elsif ( $op eq '~' | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$op eq "~" or $op eq ":" and $term =~ /[$wildcard\*\?]/
$op eq ":" and $term =~ /[$wildcard\*\?]/
MC/DC33%1/3
$op eq "~" or $op eq ":" and $term =~ /[$wildcard\*\?]/
$op eq "~"
$op eq ":"
$term =~ /[$wildcard\*\?]/
Truth table75%3/4
A or B and C
A= $op eq "~"B= $op eq ":"C= $term =~ /[$wildcard\*\?]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | || ( $op eq ':' and $term =~ m/[$wildcard\*\?]/ ) ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 26 | ▶ | $term .= $wildcard unless $term =~ m/\Q$wildcard/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 26 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | $field->wildcard_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | term => $term, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | # invert | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | elsif ( $op eq '!:' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 20 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | Lucy::Search::NOTQuery->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | negated_query => $field->term_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | term => $term, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | # standard | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 33 | push( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | @buf, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | $field->term_query_class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | field => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | term => $term, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | } # TERM | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | # possible that stop_filter results in nothing in buffer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 66 | ▶ | if ( !@buf ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 66 | ▶ | if ( @buf == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 52 | return $buf[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 14 | ▶ | my $joiner = $prefix eq '-' ? 'AND' : 'OR'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 14 | my $lucy_class = 'Lucy::Search::' . $joiner . 'Query'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 14 | return $lucy_class->new( children => \@buf ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | =head2 field_class | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | Returns "Search::Query::Field::Lucy". | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 26 | ▶ | sub field_class {'Search::Query::Field::Lucy'} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field_class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||