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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-1 / +27 lines)
Lines 1026-1031 sub clean_search_term { Link Here
1026
1026
1027
    $term = $self->_convert_index_strings_freeform($term);
1027
    $term = $self->_convert_index_strings_freeform($term);
1028
1028
1029
    # escape special characters
1030
    $term = $self->_escape_special_characters($term);
1031
1029
    # Remove unbalanced quotes
1032
    # Remove unbalanced quotes
1030
    my $unquoted = $term;
1033
    my $unquoted = $term;
1031
    my $count    = ( $unquoted =~ tr/"/ / );
1034
    my $count    = ( $unquoted =~ tr/"/ / );
Lines 1114-1119 sub clean_search_term { Link Here
1114
    return $term;
1117
    return $term;
1115
}
1118
}
1116
1119
1120
=head2 _escape_special_characters
1121
1122
    $term = $self->_escape_special_characters($term);
1123
1124
Escapes characters in $term according to "ElasticsearchEscapeCharacters" /
1125
"OpacElasticsearchEscapeCharacters" system preference setting.
1126
1127
=cut
1128
1129
sub _escape_special_characters {
1130
    my ( $self, $term ) = @_;
1131
    my $characters_to_escape;
1132
    if ( C4::Context->interface eq 'opac' ) {
1133
        $characters_to_escape = C4::Context->preference('OpacElasticsearchEscapeCharacters');
1134
    } else {
1135
        $characters_to_escape = C4::Context->preference('ElasticsearchEscapeCharacters');
1136
    }
1137
    if ($characters_to_escape) {
1138
        $characters_to_escape =~ s/\s+//g;
1139
        $term                 =~ s/[\Q$characters_to_escape\E]/\\$&/g if $characters_to_escape;
1140
    }
1141
    return $term;
1142
}
1143
1117
=head2 _query_regex_escape_process
1144
=head2 _query_regex_escape_process
1118
1145
1119
    my $query = $self->_query_regex_escape_process($query);
1146
    my $query = $self->_query_regex_escape_process($query);
1120
- 

Return to bug 28884