'Converts values from Whoosh to native Python values.
A port of the same method in pysolr, as they deal with data the same way.'

def _to_python(self, value):

    if (value == u'true'):
        return True
    elif (value == u'false'):
        return False
    if (value and isinstance(value, six.string_types)):
        possible_datetime = DATETIME_REGEX.search(value)
        if possible_datetime:
            date_values = possible_datetime.groupdict()
            for (dk, dv) in date_values.items():
                date_values[dk] = int(dv)
            return datetime(date_values[u'year'], date_values[u'month'], date_values[u'day'], date_values[u'hour'], date_values[u'minute'], date_values[u'second'])
    try:
        converted_value = json.loads(value)
        if isinstance(converted_value, (list, tuple, set, dict, six.integer_types, float, complex)):
            return converted_value
    except:
        pass
    return value
