public static function escapeString($str, $allow_wildcards=false) {
        $needles = [
            '\\', '+', '-', '=', '&&', '||', '>', '<', '!', '(', ')',
            '{', '}', '[', ']', '^', '"', '~', ':', '/', ' '
        ];
        $replacements = [
            '\\\\', '\\+', '\\-', '\\=', '\\&&', '\\||', '\\>', '\\<', '\\!', '\\(', '\\)',
            '\\{', '\\}', '\\[', '\\]', '\\^', '\\"', '\\~', '\\:', '\\/', '\\ '
        ];
        if(!$allow_wildcards) {
            $needles = array_merge($needles, ['*', '?']);
            $replacements = array_merge($replacements, ['\\*', '\\?']);
        }
        return str_replace($needles, $replacements, $str);
    }