Lines 788-794
sub _sort_field {
Link Here
|
788 |
my $query = $self->_truncate_terms($query); |
788 |
my $query = $self->_truncate_terms($query); |
789 |
|
789 |
|
790 |
Given a string query this function appends '*' wildcard to all terms except |
790 |
Given a string query this function appends '*' wildcard to all terms except |
791 |
operands. |
791 |
operands and double quoted strings. |
792 |
|
792 |
|
793 |
=cut |
793 |
=cut |
794 |
|
794 |
|
Lines 796-806
sub _truncate_terms {
Link Here
|
796 |
my ( $self, $query ) = @_; |
796 |
my ( $self, $query ) = @_; |
797 |
my @stops = qw/and or not/; |
797 |
my @stops = qw/and or not/; |
798 |
my @new_terms; |
798 |
my @new_terms; |
799 |
my @split_query = split /[\(\s\)]/, $query; |
799 |
my @quote_split = split /(["])([^"]+)\1/, $query; |
800 |
foreach my $term (@split_query) { |
800 |
#Above splits the string based on matching pairs of double quotes |
801 |
next if ( $term eq '' || $term eq ' ' ); |
801 |
#In practice we get ('','"','donald duck',' ','"','the mouse',' and pete') |
802 |
$term .= "*" unless ( ( grep { lc($term) =~ /^$_$/ } @stops ) || ( $term =~ /\*$/ ) ); |
802 |
#given the string '"donald duck" "the mouse" and pete' |
803 |
push @new_terms, $term; |
803 |
#so we ignore empties, quote the ones after a '"' and split the rest on spaces |
|
|
804 |
for (my $i=0; $i < @quote_split; $i++ ) { |
805 |
next if ( $quote_split[$i] eq '' || $quote_split[$i] eq ' ' ); |
806 |
if ( $quote_split[$i] eq '"' ){ |
807 |
$i++; |
808 |
$quote_split[$i] = '"'.$quote_split[$i].'"'; |
809 |
push @new_terms, $quote_split[$i] |
810 |
} else { |
811 |
my @space_split = split /[\(\s\)]/, $quote_split[$i]; |
812 |
foreach my $term (@space_split) { |
813 |
next if ( $term eq '' || $term eq ' ' ); |
814 |
$term .= "*" unless ( ( grep { lc($term) =~ /^$_$/ } @stops ) || ( $term =~ /\*$/ ) ); |
815 |
push @new_terms, $term; |
816 |
} |
817 |
} |
804 |
} |
818 |
} |
805 |
$query = join ' ', @new_terms; |
819 |
$query = join ' ', @new_terms; |
806 |
return $query; |
820 |
return $query; |