def alter_search(self, search):
    expression = self.kwargs.get('column')
    if (not expression):
        return
    parts = expression.split('.')
    search_types = parts[:(- 1)]
    column = parts[(- 1)]
    value = self.values.get('value')
    if (not Common.is_python3):
        if isinstance(value, unicode):
            value = value.encode('utf-8', 'ignore')
        elif isinstance(value, basestring):
            value = unicode(value, errors='ignore').encode('utf-8')
    if (not value):
        default = self.kwargs.get('default')
        if ((not self.values) and default):
            value = default
        else:
            return
    op = self.values.get('op')
    if (not op):
        op = '='
    search2 = None
    sobjects = None
    sub_search = None
    if (len(search_types) > 1):
        '\n            #TODO: replace the for loop below with this @SEARCH code which should be more efficient\n            search_types.reverse()\n            top_search_type = search_types[0]\n            search_type_str = \'.\'.join(search_types[1:])\n            expr = \'\'\'@SEARCH(%s["%s","%s"].%s)\'\'\'%(top_search_type, column, value, search_type_str)\n            search2 = Search.eval(expr)\n            sobjects = search2.get_sobjects()\n            if not sobjects:\n                # if the trail ends, then set the null filter\n                search2.set_null_filter()\n\n            '
        search_types.reverse()
        top_search_type = search_types[0]
        search_type_str = '.'.join(search_types[1:])
        if search_type_str:
            expr = ('@SEARCH(%s["%s","%s"].%s)' % (top_search_type, column, value, search_type_str))
            sub_search = Search.eval(expr)
        '\n            for search_type in search_types:\n                if sobjects == None:\n                    search2 = Search(search_type)\n                    search2.add_filter(column, value, "=")\n                    sobjects = search2.get_sobjects()\n                else:\n                    if search_type == \'connect\':\n                        related_sobjects = []\n                        from pyasm.biz import SObjectConnection\n                        connections = SObjectConnection.get_connections(sobjects)\n                        related_sobjects = SObjectConnection.get_sobjects(connections)\n                        """    \n                        for sobject in sobjects:\n                            connections, sobjects = SObjectConnection.get_connected_sobjects(sobject)\n                            related_sobjects.extend(sobjects)\n                        """    \n                        sobjects = related_sobjects[:]\n                    else:\n                        search2 = Search(search_type)\n                        search2.add_relationship_filters(sobjects)\n                        sobjects = search2.get_sobjects()\n\n                if not sobjects:\n                    # if the trail ends, then set the null filter and exit\n                    search.set_null_filter()\n                    return\n           '
    elif (not search_types):
        if (op == '!='):
            search.add_op('begin')
            search.add_filter(column, value, op)
            search.add_filter(column, None)
            search.add_op('or')
        elif (op in ['~', 'EQI']):
            filters = [[column, 'EQI', value]]
            search.add_op_filters(filters)
        elif (op == 'is on'):
            search.add_day_filter(column, value)
        else:
            search.add_filter(column, value, op)
        return
    else:
        search_type = search_types[0]
        try:
            search2 = Search(search_type)
            if value:
                if (op == 'exists'):
                    search.add_relationship_search_filter(search2, op=value)
                    return
                elif (op == '!='):
                    search2.add_op('begin')
                    search2.add_filter(column, value, op)
                    search2.add_filter(column, None)
                    search2.add_op('or')
                elif (op in ['~', 'EQI']):
                    filters = [[column, 'EQI', value]]
                    search2.add_op_filters(filters)
                elif (op == 'is on'):
                    search2.add_day_filter(column, value)
                else:
                    search2.add_filter(column, value, op)
            use_multidb = False
            search.add_relationship_search_filter(search2, op='in', use_multidb=use_multidb)
        except SearchException as e:
            raise SearchException(('[%s] in simple search definition may have syntax error. %s ' % (expression, e.__str__())))
        return
    if (op == '='):
        op = 'in'
    else:
        op = 'not in'
    if sobjects:
        search.add_relationship_filters(sobjects, op=op)
    elif sub_search:
        if (search_types[(- 1)] == 'connect'):
            search.add_search_filter('id', sub_search, op=op)
        else:
            search.add_relationship_search_filter(sub_search, op=op)
    else:
        search.set_null_filter()
def alter_search(self, search):
    expression = self.kwargs.get('column')
    if (not expression):
        return
    parts = expression.split('.')
    search_types = parts[:(- 1)]
    column = parts[(- 1)]
    value = self.values.get('value')
    if (not Common.is_python3):
        if isinstance(value, unicode):
            value = value.encode('utf-8', 'ignore')
        elif isinstance(value, basestring):
            value = unicode(value, errors='ignore').encode('utf-8')
    if (not value):
        default = self.kwargs.get('default')
        if ((not self.values) and default):
            value = default
        else:
            return
    op = self.values.get('op')
    if (not op):
        op = '='
    search2 = None
    sobjects = None
    sub_search = None
    if (len(search_types) > 1):
        '\n            #TODO: replace the for loop below with this @SEARCH code which should be more efficient\n            search_types.reverse()\n            top_search_type = search_types[0]\n            search_type_str = \'.\'.join(search_types[1:])\n            expr = \'\'\'@SEARCH(%s["%s","%s"].%s)\'\'\'%(top_search_type, column, value, search_type_str)\n            search2 = Search.eval(expr)\n            sobjects = search2.get_sobjects()\n            if not sobjects:\n                # if the trail ends, then set the null filter\n                search2.set_null_filter()\n\n            '
        search_types.reverse()
        top_search_type = search_types[0]
        search_type_str = '.'.join(search_types[1:])
        if search_type_str:
            expr = ('@SEARCH(%s["%s","%s"].%s)' % (top_search_type, column, value, search_type_str))
            sub_search = Search.eval(expr)
        '\n            for search_type in search_types:\n                if sobjects == None:\n                    search2 = Search(search_type)\n                    search2.add_filter(column, value, "=")\n                    sobjects = search2.get_sobjects()\n                else:\n                    if search_type == \'connect\':\n                        related_sobjects = []\n                        from pyasm.biz import SObjectConnection\n                        connections = SObjectConnection.get_connections(sobjects)\n                        related_sobjects = SObjectConnection.get_sobjects(connections)\n                        "    \n                        for sobject in sobjects:\n                            connections, sobjects = SObjectConnection.get_connected_sobjects(sobject)\n                            related_sobjects.extend(sobjects)\n                        "    \n                        sobjects = related_sobjects[:]\n                    else:\n                        search2 = Search(search_type)\n                        search2.add_relationship_filters(sobjects)\n                        sobjects = search2.get_sobjects()\n\n                if not sobjects:\n                    # if the trail ends, then set the null filter and exit\n                    search.set_null_filter()\n                    return\n           '
    elif (not search_types):
        if (op == '!='):
            search.add_op('begin')
            search.add_filter(column, value, op)
            search.add_filter(column, None)
            search.add_op('or')
        elif (op in ['~', 'EQI']):
            filters = [[column, 'EQI', value]]
            search.add_op_filters(filters)
        elif (op == 'is on'):
            search.add_day_filter(column, value)
        else:
            search.add_filter(column, value, op)
        return
    else:
        search_type = search_types[0]
        try:
            search2 = Search(search_type)
            if value:
                if (op == 'exists'):
                    search.add_relationship_search_filter(search2, op=value)
                    return
                elif (op == '!='):
                    search2.add_op('begin')
                    search2.add_filter(column, value, op)
                    search2.add_filter(column, None)
                    search2.add_op('or')
                elif (op in ['~', 'EQI']):
                    filters = [[column, 'EQI', value]]
                    search2.add_op_filters(filters)
                elif (op == 'is on'):
                    search2.add_day_filter(column, value)
                else:
                    search2.add_filter(column, value, op)
            use_multidb = False
            search.add_relationship_search_filter(search2, op='in', use_multidb=use_multidb)
        except SearchException as e:
            raise SearchException(('[%s] in simple search definition may have syntax error. %s ' % (expression, e.__str__())))
        return
    if (op == '='):
        op = 'in'
    else:
        op = 'not in'
    if sobjects:
        search.add_relationship_filters(sobjects, op=op)
    elif sub_search:
        if (search_types[(- 1)] == 'connect'):
            search.add_search_filter('id', sub_search, op=op)
        else:
            search.add_relationship_search_filter(sub_search, op=op)
    else:
        search.set_null_filter()