import re


def strip_multi_value_operators(string):
    """The Search API will parse a query like `PYTHON OR` as an incomplete
    multi-value query, and raise an error as it expects a second argument
    in this query language format. To avoid this we strip the `AND` / `OR`
    operators tokens from the end of query string. This does not stop
    a valid multi value query executing as expected.
    """
    # the search API source code lists many operators in the tokenNames
    # iterable, but it feels cleaner for now to explicitly name only the ones
    # we are interested in here
    if string:
        string = re.sub(r'^(OR|AND)', '', string)
        string = re.sub(r'(OR|AND)$', '', string)
        string = string.strip()
    return string