| 1 | package Plucene::Search::PrefixQuery; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | Plucene::Search::TermQuery - a query that matches terms beginning with a string | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # isa Plucene::Search::Query | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | $prefix_query->normalize($norm); | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | my $ssw = $prefix_query->sum_squared_weights($searcher); | ||||||||||||||||||||||||||||||||||||||||||
| 14 | my $as_string = $prefix_query->to_string($field); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | A query that matches a document containing terms I<beginning> with the | ||||||||||||||||||||||||||||||||||||||||||
| 19 | given string. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use base 'Plucene::Search::Query'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use Plucene::Search::BooleanQuery; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Plucene::Search::TermQuery; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | __PACKAGE__->mk_accessors(qw/ prefix reader /); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | sub prepare { $_[0]->reader($_[1]) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # This returns the underlying boolean query. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 9 | ▶ | sub _query { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_query: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | return $self->{query} if exists $self->{query}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 3 | my $q = new Plucene::Search::BooleanQuery; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | my $prefix = $self->prefix; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 3 | my $enum = $self->reader->terms($prefix); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 3 | my ($field, $text) = ($prefix->field, $prefix->text); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 12 | my $term = $enum->term; | |||||||||||||||||||||||||||||||||||||||||
| 44 | goto DONE | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 12 | ▶ | unless $term | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$term and $term->text =~ /^\Q$text\E/ and $term->field eq $field
$term and $term->text =~ /^\Q$text\E/
MC/DC33%1/3
$term and $term->text =~ /^\Q$text\E/ and $term->field eq $field
$term
$term->text =~ /^\Q$text\E/
$term->field eq $field
Truth table50%2/4
A and B and C
A= $termB= $term->text =~ /^\Q$text\E/C= $term->field eq $field
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | and $term->text =~ /^\Q$text/ | ||||||||||||||||||||||||||||||||||||||||||
| 47 | and $term->field eq $field; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | my $tq = Plucene::Search::TermQuery->new({ term => $term }); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 9 | $tq->boost($self->boost); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | $q->add($tq, 0, 0); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } while $enum->next; | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 3 | DONE: $self->{query} = $q; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | =head2 to_string | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | $q->to_string | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | Convert the query to a readable string format | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | =head2 sum_squared_weights | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | The sum sqaured weights of the query. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | =head2 normalize | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | Normalize the query. | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | my ($self, $field) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | my $s = ""; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | $s = $self->prefix->field . ":" if $self->prefix->field ne $field; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | $s .= $self->prefix->text . "*"; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | $s .= "^" . $self->boost unless $self->boost == 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | $s; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 3 | ▶ | sub sum_squared_weights { shift->_query->sum_squared_weights(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sum_squared_weights: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | sub normalize { shift->_query->normalize(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | sub _scorer { shift->_query->_scorer(@_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scorer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||