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

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

Return to bug 28316