Commit 9371bd04 authored by Vincent Pelletier's avatar Vincent Pelletier

Define a new "not like" operator.

Generate automaticaly "not like" operator use in KeywordKey when given operator is "!=" and value contains at least one "%".
Update test to chekc for "not like" operator.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25817 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 478980df
......@@ -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'),
......
......@@ -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)
......@@ -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'})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment