View | Details | Raw Unified | Return to bug 18374
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-1 / +24 lines)
Lines 83-88 sub build_query { Link Here
83
    my $fuzzy_enabled    = C4::Context->preference("QueryFuzzy")           || 0;
83
    my $fuzzy_enabled    = C4::Context->preference("QueryFuzzy")           || 0;
84
84
85
    $query = '*' unless defined $query;
85
    $query = '*' unless defined $query;
86
    $query = $self->_truncate_terms($query) if ( $auto_truncation );
86
87
87
    my $res;
88
    my $res;
88
    $res->{query} = {
89
    $res->{query} = {
Lines 779-782 sub _sort_field { Link Here
779
    return $f;
780
    return $f;
780
}
781
}
781
782
783
=head2 _truncate_terms
784
785
    my $query = $self->_truncate_terms($query);
786
787
Given a string query this function appends '*' wildcard  to all terms except
788
operands.
789
790
=cut
791
792
sub _truncate_terms {
793
    my ($self, $query) = @_;
794
    my @stops = qw/and or not/;
795
    my @new_terms;
796
    my @split_query = split /[\(\s\)]/, $query ;
797
    foreach  my $term ( @split_query ) {
798
        next if ($term eq '' || $term eq ' ' ) ;
799
        $term .= "*" unless ( ( grep { $term =~ /$_/ } @stops ) || ($term =~ /\*$/ ) );
800
        push @new_terms, $term;
801
    }
802
    $query=join ' ' ,@new_terms;
803
    return $query;
804
}
805
782
1;
806
1;
783
- 

Return to bug 18374