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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-1 / +13 lines)
Lines 938-943 sub _clean_search_term { Link Here
938
    }
938
    }
939
    $term = $self->_query_regex_escape_process($term);
939
    $term = $self->_query_regex_escape_process($term);
940
940
941
    # because of _truncate_terms and if QueryAutoTruncate enabled
942
    # we will have any special operators ruined by _truncate_terms:
943
    # for ex. search for "test [6 TO 7]" will be converted to "test* [6* TO* 7]"
944
    # so no reason to keep ranges in QueryAutoTruncate==true case:
945
    my $truncate = C4::Context->preference("QueryAutoTruncate") || 0;
946
    unless($truncate) {
947
        # replace all ranges with any square/curly brackets combinations to temporary substitutions (ex: "{a TO b]"" -> "~~LC~~a TO b~~RS~~")
948
        $term =~ s/(?<!\\)((?:[\\]{2})*)(\{|\[)([^\s\[\]\{\}]+ TO [^\s\[\]\{\}]+(?<!\\)(?:[\\]{2})*)(\}|\])/$1.'~~L'.($2 eq '[' ? 'S':'C').'~~'.$3.'~~R'.($4 eq ']' ? 'S':'C').'~~'/ge;
949
    }
941
    # save all regex contents away before escaping brackets:
950
    # save all regex contents away before escaping brackets:
942
    my @saved_regexes;
951
    my @saved_regexes;
943
    my $rgx_i = 0;
952
    my $rgx_i = 0;
Lines 973-978 sub _clean_search_term { Link Here
973
    for (my $i = 0; $i < @saved_regexes; $i++) {
982
    for (my $i = 0; $i < @saved_regexes; $i++) {
974
        $term =~ s/~~XI$i~~/$saved_regexes[$i]/;
983
        $term =~ s/~~XI$i~~/$saved_regexes[$i]/;
975
    }
984
    }
985
    unless($truncate) {
986
        # restore temporary weird substitutions back to normal brackets
987
        $term =~ s/~~L(C|S)~~([^\s\[\]\{\}]+ TO [^\s\[\]\{\}]+)~~R(C|S)~~/($1 eq 'S' ? '[':'{').$2.($3 eq 'S' ? ']':'}')/ge;
988
    }
976
    return $term;
989
    return $term;
977
}
990
}
978
991
979
- 

Return to bug 28316