diff --git a/product/ZSQLCatalog/Operator/ComparisonOperator.py b/product/ZSQLCatalog/Operator/ComparisonOperator.py index d990fadb92cd4534499e79594005fc2ddf9002dc..8755bcd36fff424bcb8eb457d00b36bc85c91d5d 100644 --- a/product/ZSQLCatalog/Operator/ComparisonOperator.py +++ b/product/ZSQLCatalog/Operator/ComparisonOperator.py @@ -138,6 +138,7 @@ operator_dict = { '<=': MonovaluedComparisonOperator('<='), '>=': MonovaluedComparisonOperator('>='), 'like': MonovaluedComparisonOperator('like'), + 'not like': MonovaluedComparisonOperator('not like', '!='), 'match': MatchComparisonOperator('match'), 'match_boolean': MatchComparisonOperator('match_boolean', mode=' IN BOOLEAN MODE'), 'match_expansion': MatchComparisonOperator('match_expansion', mode=' WITH QUERY EXPANSION'), diff --git a/product/ZSQLCatalog/SearchKey/KeywordKey.py b/product/ZSQLCatalog/SearchKey/KeywordKey.py index 3d9aa8e14c2409fded027bed5a6da52041c400be..5912d3d7e977e12716013849483aa083e3bf5203 100644 --- a/product/ZSQLCatalog/SearchKey/KeywordKey.py +++ b/product/ZSQLCatalog/SearchKey/KeywordKey.py @@ -32,6 +32,7 @@ from SearchKey import SearchKey from Products.ZSQLCatalog.SearchText import parse from Products.ZSQLCatalog.Interface.ISearchKey import ISearchKey from Interface.Verify import verifyClass +from Products.ZSQLCatalog.Query.SimpleQuery import SimpleQuery class KeywordKey(SearchKey): """ @@ -44,5 +45,25 @@ class KeywordKey(SearchKey): def parseSearchText(self, value): return parse(value) + def _buildQuery(self, operator_value_dict, logical_operator, parsed, group): + """ + Treat "!=" operator specialy: + - if the value contains at least one "%", change operator into "not like" + - otherwise, let it go untouched + """ + result = [] + if '!=' in operator_value_dict: + column = self.getColumn() + original_different_list = operator_value_dict.pop('!=') + different_list = [] + for value in original_different_list: + if isinstance(value, basestring) and '%' in value: + result.append(SimpleQuery(search_key=self, group=group, operator='not like', **{column: value})) + else: + different_list.append(value) + if len(different_list): + operator_value_dict['!='] = different_list + return result + SearchKey._buildQuery(self, operator_value_dict, logical_operator, parsed, group) + verifyClass(ISearchKey, KeywordKey) diff --git a/product/ZSQLCatalog/tests/testSQLCatalog.py b/product/ZSQLCatalog/tests/testSQLCatalog.py index 0aff1c7c1310a3027c8458f9a64da653bd8c17cc..8fbcb2f0df116a6c4bff2d9e54ee176c055ae0bf 100644 --- a/product/ZSQLCatalog/tests/testSQLCatalog.py +++ b/product/ZSQLCatalog/tests/testSQLCatalog.py @@ -289,9 +289,7 @@ class TestSQLCatalog(unittest.TestCase): {column: '"a b"'}) self.catalog(ReferenceQuery(ReferenceQuery(operator='!=', keyword='a'), operator='and'), {column: '!=a'}) - self.catalog(ReferenceQuery( - ReferenceQuery(ReferenceQuery(operator='like', keyword='%a'), operator='not') - , operator='and'), + self.catalog(ReferenceQuery(ReferenceQuery(operator='not like', keyword='%a'), operator='and'), {column: '!=%a'}) self.catalog(ReferenceQuery(ReferenceQuery(operator='like', keyword='%a'), operator='and'), {column: '%a'})