Commit 8b5c59b9 authored by Jean-Paul Smets's avatar Jean-Paul Smets

more spaces removed

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@19216 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 9bcb5a93
...@@ -33,14 +33,14 @@ from DateTime import DateTime ...@@ -33,14 +33,14 @@ from DateTime import DateTime
from SearchKey import SearchKey from SearchKey import SearchKey
from pprint import pprint from pprint import pprint
class DateTimeKey(SearchKey): class DateTimeKey(SearchKey):
""" DateTimeKey key is an ERP5 portal_catalog search key which is used to render """ DateTimeKey key is an ERP5 portal_catalog search key which is used to render
SQL expression that will try to match values in DateTime MySQL columns. SQL expression that will try to match values in DateTime MySQL columns.
It supports following special operator ['=', '%', '>' , '>=', '<', '<='] in It supports following special operator ['=', '%', '>' , '>=', '<', '<='] in
addition to main logical operators like ['OR', 'or', 'AND', 'and']. addition to main logical operators like ['OR', 'or', 'AND', 'and'].
Note: because all ERP5 datetime values are indexed in MySQL in 'UTC' Note: because all ERP5 datetime values are indexed in MySQL in 'UTC'
the respective passed date will be first converted to 'UTC' before inserted into the respective passed date will be first converted to 'UTC' before inserted into
respective SQL query! respective SQL query!
...@@ -48,15 +48,15 @@ class DateTimeKey(SearchKey): ...@@ -48,15 +48,15 @@ class DateTimeKey(SearchKey):
* '15/01/2008' --> "delivery.start_date = '2008-01-14 22:00'" * '15/01/2008' --> "delivery.start_date = '2008-01-14 22:00'"
* '>=15/01/2008' --> "delivery.start_date >= '2008-01-14 22:00'" * '>=15/01/2008' --> "delivery.start_date >= '2008-01-14 22:00'"
* '>=15/01/2008 or <=20/01/2008' * '>=15/01/2008 or <=20/01/2008'
--> "delivery.start_date >= '2008-01-14 22:00' or delivery.start_date<='2008-01-19 22:00'" --> "delivery.start_date >= '2008-01-14 22:00' or delivery.start_date<='2008-01-19 22:00'"
* '>=15/01/2008 10:00 GMT+02 OR <=20/01/2008 05:12 Universal' * '>=15/01/2008 10:00 GMT+02 OR <=20/01/2008 05:12 Universal'
--> -->
"delivery.start_date >= '2008-01-15 08:00 Universal' "delivery.start_date >= '2008-01-15 08:00 Universal'
OR OR
delivery.start_date <= '2008-01-20 05:12 Universal' delivery.start_date <= '2008-01-20 05:12 Universal'
" "
""" """
...@@ -65,7 +65,7 @@ class DateTimeKey(SearchKey): ...@@ -65,7 +65,7 @@ class DateTimeKey(SearchKey):
'GREATERTHAN', 'GREATERTHANEQUAL', 'GREATERTHAN', 'GREATERTHANEQUAL',
'LESSTHAN', 'LESSTHANEQUAL') 'LESSTHAN', 'LESSTHANEQUAL')
sub_operators = ('GREATERTHAN', 'GREATERTHANEQUAL', sub_operators = ('GREATERTHAN', 'GREATERTHANEQUAL',
'LESSTHAN', 'LESSTHANEQUAL', 'NOT', 'EQUAL',) 'LESSTHAN', 'LESSTHANEQUAL', 'NOT', 'EQUAL',)
def t_OR(self, t): def t_OR(self, t):
...@@ -86,15 +86,15 @@ class DateTimeKey(SearchKey): ...@@ -86,15 +86,15 @@ class DateTimeKey(SearchKey):
t.value = t.value.upper().strip() t.value = t.value.upper().strip()
return t return t
t_GREATERTHANEQUAL = r'>=' t_GREATERTHANEQUAL = r'>='
t_LESSTHANEQUAL = r'<=' t_LESSTHANEQUAL = r'<='
t_GREATERTHAN = r'>' t_GREATERTHAN = r'>'
t_LESSTHAN = r'<' t_LESSTHAN = r'<'
t_EQUAL = r'=' t_EQUAL = r'='
t_DATE = r'\d{1,4}[(/|\.|\-) /.]\d{1,4}[(/|\.|\-) /.]\d{1,4}((\s.)*\d{0,2}:\d{0,2}(:\d{0,2})?)?(\sUniversal|\sGMT\+\d\d)?|\d\d\d\d%?' t_DATE = r'\d{1,4}[(/|\.|\-) /.]\d{1,4}[(/|\.|\-) /.]\d{1,4}((\s.)*\d{0,2}:\d{0,2}(:\d{0,2})?)?(\sUniversal|\sGMT\+\d\d)?|\d\d\d\d%?'
def quoteSQLString(self, value, format): def quoteSQLString(self, value, format):
""" Return a quoted string of the value. """ Return a quoted string of the value.
Make sure to convert it to UTC first.""" Make sure to convert it to UTC first."""
if getattr(value, 'ISO', None) is not None: if getattr(value, 'ISO', None) is not None:
value = "'%s'" % value.toZone('UTC').ISO() value = "'%s'" % value.toZone('UTC').ISO()
...@@ -122,7 +122,7 @@ class DateTimeKey(SearchKey): ...@@ -122,7 +122,7 @@ class DateTimeKey(SearchKey):
# add days ofset accordingly # add days ofset accordingly
format = '%%%s/%%m/%%d' %format format = '%%%s/%%m/%%d' %format
date_value = '%s/01/01' %date_value date_value = '%s/01/01' %date_value
days_offset_map = {'=' : 366, '>' : 366, days_offset_map = {'=' : 366, '>' : 366,
'>=' : 366, '<': -366, '<=':-366} '>=' : 366, '<': -366, '<=':-366}
days_offset = days_offset_map[sub_operator] days_offset = days_offset_map[sub_operator]
...@@ -143,10 +143,10 @@ class DateTimeKey(SearchKey): ...@@ -143,10 +143,10 @@ class DateTimeKey(SearchKey):
if sub_operator == '=': if sub_operator == '=':
# transform to range 'key >= date AND date < key' # transform to range 'key >= date AND date < key'
query_kw = {key: (date_value, date_value + days_offset,), query_kw = {key: (date_value, date_value + days_offset,),
'range': 'minmax'} 'range': 'minmax'}
else: else:
query_kw = {key: date_value + days_offset, query_kw = {key: date_value + days_offset,
'range': sub_operator} 'range': sub_operator}
query_kw['type'] = 'date' query_kw['type'] = 'date'
else: else:
# not a valid date, try to get an year range # not a valid date, try to get an year range
...@@ -159,7 +159,7 @@ class DateTimeKey(SearchKey): ...@@ -159,7 +159,7 @@ class DateTimeKey(SearchKey):
date_value = DateTime(date_value).toZone('UTC') date_value = DateTime(date_value).toZone('UTC')
query_kw = {key: (date_value, date_value + 366,), query_kw = {key: (date_value, date_value + 366,),
'type': 'date', 'type': 'date',
'range': 'minmax'} 'range': 'minmax'}
# append only if it was possible to generate query # append only if it was possible to generate query
if query_kw is not None: if query_kw is not None:
...@@ -167,7 +167,7 @@ class DateTimeKey(SearchKey): ...@@ -167,7 +167,7 @@ class DateTimeKey(SearchKey):
# join query list in one really big ComplexQuery # join query list in one really big ComplexQuery
if len(query_list): if len(query_list):
complex_query = ComplexQuery(*query_list, complex_query = ComplexQuery(*query_list,
**{'operator': 'AND'}) **{'operator': 'AND'})
return complex_query return complex_query
...@@ -188,7 +188,7 @@ class DateTimeKey(SearchKey): ...@@ -188,7 +188,7 @@ class DateTimeKey(SearchKey):
## operator_value = operator.value ## operator_value = operator.value
## where_expressions.append('%s' %operator_value) ## where_expressions.append('%s' %operator_value)
## if len(tokens): ## if len(tokens):
## # no it's not a stand alone expression, ## # no it's not a stand alone expression,
## # determine it from list of tokens ## # determine it from list of tokens
## operator_value, sub_tokens = self.getOperatorForTokenList(tokens) ## operator_value, sub_tokens = self.getOperatorForTokenList(tokens)
## row_tokens_values = [self.quoteSQLString(x.value, format) for x in sub_tokens] ## row_tokens_values = [self.quoteSQLString(x.value, format) for x in sub_tokens]
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
from SearchKey import SearchKey from SearchKey import SearchKey
from pprint import pprint from pprint import pprint
...@@ -35,7 +35,7 @@ class DefaultKey(SearchKey): ...@@ -35,7 +35,7 @@ class DefaultKey(SearchKey):
It supports following special operator ['=', '%', '>' , '>=', '<', '<='] in It supports following special operator ['=', '%', '>' , '>=', '<', '<='] in
addition to main logical operators like ['OR', 'or', 'AND', 'and']. addition to main logical operators like ['OR', 'or', 'AND', 'and'].
Examples for title column: Examples for title column:
* 'foo or bar' --> "title = 'foo' OR title = 'bar'" * 'foo or bar' --> "title = 'foo' OR title = 'bar'"
* 'foo or =bar' --> "title = 'foo' OR title = 'bar'" * 'foo or =bar' --> "title = 'foo' OR title = 'bar'"
* '%foo% or bar' --> "title = '%foo%' OR title = 'bar'" * '%foo% or bar' --> "title = '%foo%' OR title = 'bar'"
...@@ -48,10 +48,10 @@ class DefaultKey(SearchKey): ...@@ -48,10 +48,10 @@ class DefaultKey(SearchKey):
default_key_type = 'default' default_key_type = 'default'
tokens = ('OR', 'AND', 'NOT', 'WORDSET', 'WORD', tokens = ('OR', 'AND', 'NOT', 'WORDSET', 'WORD',
'GREATERTHAN', 'GREATERTHANEQUAL', 'GREATERTHAN', 'GREATERTHANEQUAL',
'LESSTHAN', 'LESSTHANEQUAL') 'LESSTHAN', 'LESSTHANEQUAL')
sub_operators = ('GREATERTHAN', 'GREATERTHANEQUAL', sub_operators = ('GREATERTHAN', 'GREATERTHANEQUAL',
'LESSTHAN', 'LESSTHANEQUAL', 'NOT') 'LESSTHAN', 'LESSTHANEQUAL', 'NOT')
...@@ -68,19 +68,19 @@ class DefaultKey(SearchKey): ...@@ -68,19 +68,19 @@ class DefaultKey(SearchKey):
# operator must have leading and trailing ONLY one white space character # operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD # otherwise it's treated as a WORD
t.value = 'AND' t.value = 'AND'
return t return t
def t_NOT(self, t): def t_NOT(self, t):
r'(\s+NOT\s+|\s+not\s+|!=)' r'(\s+NOT\s+|\s+not\s+|!=)'
# operator must have leading and trailing ONLY one white space character # operator must have leading and trailing ONLY one white space character
# otherwise it's treated as a WORD # otherwise it's treated as a WORD
t.value = '!=' t.value = '!='
return t return t
t_GREATERTHANEQUAL = r'>=' t_GREATERTHANEQUAL = r'>='
t_LESSTHANEQUAL = r'<=' t_LESSTHANEQUAL = r'<='
t_GREATERTHAN = r'>' t_GREATERTHAN = r'>'
t_LESSTHAN = r'<' t_LESSTHAN = r'<'
def t_WORD(self, t): def t_WORD(self, t):
r'[\x7F-\xFF\w\d\/~!@#$%^&*()_+\n][\x7F-\xFF\w\d\/~!@#$%^&*()_+\n]*' r'[\x7F-\xFF\w\d\/~!@#$%^&*()_+\n][\x7F-\xFF\w\d\/~!@#$%^&*()_+\n]*'
...@@ -98,7 +98,7 @@ class DefaultKey(SearchKey): ...@@ -98,7 +98,7 @@ class DefaultKey(SearchKey):
# and starting/ending with " # and starting/ending with "
value = t.value.replace('"', '').strip() value = t.value.replace('"', '').strip()
t.value = "%s" %value t.value = "%s" %value
return t return t
def quoteSQLString(self, value, format): def quoteSQLString(self, value, format):
""" Return a quoted string of the value. """ """ Return a quoted string of the value. """
...@@ -139,9 +139,9 @@ class DefaultKey(SearchKey): ...@@ -139,9 +139,9 @@ class DefaultKey(SearchKey):
## operator_value = operator.value ## operator_value = operator.value
## where_expressions.append('%s' %operator_value) ## where_expressions.append('%s' %operator_value)
## if len(tokens): ## if len(tokens):
## # no it's not a stand alone expression, ## # no it's not a stand alone expression,
## # determine it from list of tokens ## # determine it from list of tokens
## operator_value, sub_tokens = self.getOperatorForTokenList(tokens) ## operator_value, sub_tokens = self.getOperatorForTokenList(tokens)
## row_tokens_values = [x.value for x in sub_tokens] ## row_tokens_values = [x.value for x in sub_tokens]
## where_expressions.append("%s %s '%s'" %(key, operator_value, ' '.join(row_tokens_values))) ## where_expressions.append("%s %s '%s'" %(key, operator_value, ' '.join(row_tokens_values)))
## return where_expressions, select_expressions ## return where_expressions, select_expressions
...@@ -33,13 +33,13 @@ SEARCH_MODE_MAPPING = {'in_boolean_mode': 'IN BOOLEAN MODE', ...@@ -33,13 +33,13 @@ SEARCH_MODE_MAPPING = {'in_boolean_mode': 'IN BOOLEAN MODE',
class FullTextKey(SearchKey): class FullTextKey(SearchKey):
""" FullTextKey key is an ERP5 portal_catalog search key which is used to render """ FullTextKey key is an ERP5 portal_catalog search key which is used to render
SQL expression that will try match all possible values using SQL expression that will try match all possible values using
MySQL's fulltext search support. MySQL's fulltext search support.
See syntax see MySQL's FullText search reference: See syntax see MySQL's FullText search reference:
http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html
""" """
tokens = ('PLUS', 'MINUS', 'WORD', 'GREATERTHAN', 'LESSTHAN', 'LEFTPARENTHES', tokens = ('PLUS', 'MINUS', 'WORD', 'GREATERTHAN', 'LESSTHAN', 'LEFTPARENTHES',
'RIGHTPARENTHES', 'TILDE', 'ASTERISK', 'DOUBLEQUOTE',) 'RIGHTPARENTHES', 'TILDE', 'ASTERISK', 'DOUBLEQUOTE',)
# SQL expressions patterns # SQL expressions patterns
...@@ -50,12 +50,12 @@ class FullTextKey(SearchKey): ...@@ -50,12 +50,12 @@ class FullTextKey(SearchKey):
t_PLUS = r'(\+)' t_PLUS = r'(\+)'
t_MINUS = r'(\-)' t_MINUS = r'(\-)'
t_GREATERTHAN = r'(\>)' t_GREATERTHAN = r'(\>)'
t_LESSTHAN = r'(\<)' t_LESSTHAN = r'(\<)'
t_LEFTPARENTHES = r'(\()' t_LEFTPARENTHES = r'(\()'
t_RIGHTPARENTHES = r'(\))' t_RIGHTPARENTHES = r'(\))'
t_TILDE = r'(\~)' t_TILDE = r'(\~)'
t_ASTERISK = r'(\*)' t_ASTERISK = r'(\*)'
t_DOUBLEQUOTE = r'(\")' t_DOUBLEQUOTE = r'(\")'
def t_WORD(self, t): def t_WORD(self, t):
r'[\x7F-\xFF\w\d\/!@#$%^&_][\x7F-\xFF\w\d\/!@#$%^&_]*' r'[\x7F-\xFF\w\d\/!@#$%^&_][\x7F-\xFF\w\d\/!@#$%^&_]*'
...@@ -65,15 +65,15 @@ class FullTextKey(SearchKey): ...@@ -65,15 +65,15 @@ class FullTextKey(SearchKey):
t.value = "'%s'" %word_value t.value = "'%s'" %word_value
return t return t
def buildSQLExpression(self, key, value, def buildSQLExpression(self, key, value,
format=None, mode=None, range_value=None, stat__=None): format=None, mode=None, range_value=None, stat__=None):
""" Analize token list and generate SQL expressions.""" """ Analize token list and generate SQL expressions."""
tokens = self.tokenize(value) tokens = self.tokenize(value)
# based on type tokens we may switch to different search mode # based on type tokens we may switch to different search mode
mode = SEARCH_MODE_MAPPING.get(mode, '') mode = SEARCH_MODE_MAPPING.get(mode, '')
if mode == '': if mode == '':
# determine it based on list of tokens i.e if we have only words # determine it based on list of tokens i.e if we have only words
# leave as its but if we have '-' or '+' use boolean mode # leave as its but if we have '-' or '+' use boolean mode
for token in tokens: for token in tokens:
if token.type != 'WORD': if token.type != 'WORD':
mode = SEARCH_MODE_MAPPING['in_boolean_mode'] mode = SEARCH_MODE_MAPPING['in_boolean_mode']
...@@ -90,7 +90,7 @@ class FullTextKey(SearchKey): ...@@ -90,7 +90,7 @@ class FullTextKey(SearchKey):
where_expression = self.where_match_against %(key, value, mode) where_expression = self.where_match_against %(key, value, mode)
if not stat__: if not stat__:
# stat__ is an internal implementation artifact to prevent adding # stat__ is an internal implementation artifact to prevent adding
# select_expression for countFolder # select_expression for countFolder
select_expression_list = [self.select_match_against_as %(key, value, mode, relevance_key1),] select_expression_list = [self.select_match_against_as %(key, value, mode, relevance_key1),]
if relevance_key2 is not None: if relevance_key2 is not None:
select_expression_list.append(self.select_match_against_as %(key, value, mode, relevance_key2)) select_expression_list.append(self.select_match_against_as %(key, value, mode, relevance_key2))
......
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