import re


def opensearch_clean(f):
    """
    Some opensearch clients send along optional parameters from the opensearch
    description when they're not needed. For example:
    
        state={openoni:state?}

    These can cause search results not to come back, and even can cause Solr's 
    query parsing to throw an exception, so it's best to remove them when
    present.
    """
    def f1(request, **kwargs):
        new_get = request.GET.copy()
        for k, v in list(new_get.items()):
            if type(v) == str and re.match(r'^\{.+\?\}$', v):
                new_get.pop(k)
        request.GET = new_get
        return f(request, **kwargs)
    return f1