def METHOD_NAME(self, query):
    def escape(v):
        # TODO: improve this
        return v.replace('"', r'\"').replace("(", "\\(").replace(")", "\\)")
    def escape_value(v):
        if isinstance(v, tuple):  # hack for supporting range
            return f"[{escape(v[0])} TO {escape(v[1])}]"
        elif isinstance(v, list):  # one of
            return "(%s)" % " OR ".join(escape_value(x) for x in v)
        else:
            return '"%s"' % escape(v)
    if isinstance(query, dict):
        op = query.pop("_op", "AND")
        if op.upper() != "OR":
            op = "AND"
        op = " " + op + " "
        q = op.join(f'{k}:{escape_value(v)}' for k, v in query.items())
    else:
        q = query
    return q