'Process filters in POST, interprets URL filter expressions
in POST vars (if multipart), or from JSON request body (if
not multipart or $search=ajax).
NB: overrides S3Request method as GET (r.http) to trigger
the correct method handlers, but will not change
current.request.env.request_method'

def __search(self):

    get_vars = self.get_vars
    content_type = (self.env.get('content_type') or '')
    mode = get_vars.get('$search')
    if mode:
        self.http = 'GET'
    if (content_type == 'application/x-www-form-urlencoded'):
        filters = self.post_vars
        decode = None
    elif ((mode == 'ajax') or (content_type[:10] != 'multipart/')):
        s = self.body
        s.seek(0)
        try:
            filters = json.load(s)
        except ValueError:
            filters = {}
        if (not isinstance(filters, dict)):
            filters = {}
        decode = None
    else:
        filters = self.post_vars
        decode = json.loads
    get_vars = Storage(get_vars)
    post_vars = Storage(self.post_vars)
    del get_vars['$search']
    for (k, v) in filters.items():
        k0 = k[0]
        if ((k == '$filter') or ((k0 != '_') and (('.' in k) or ((k0 == '(') and (')' in k))))):
            try:
                value = (decode(v) if decode else v)
            except ValueError:
                continue
            if (type(value) is list):
                value = [(str(item) if (not isinstance(item, basestring)) else item) for item in value]
            elif (not isinstance(value, basestring)):
                value = str(value)
            get_vars[k] = value
            if (k in post_vars):
                del post_vars[k]
    self.get_vars = get_vars
    self.post_vars = post_vars
    self.vars = get_vars.copy()
    self.vars.update(self.post_vars)
