[Erp5-report] r19706 - in /erp5/trunk/products/ZSQLCatalog: SearchKey/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Mar 5 19:37:53 CET 2008


Author: jerome
Date: Wed Mar  5 19:37:53 2008
New Revision: 19706

URL: http://svn.erp5.org?rev=19706&view=rev
Log:
Simplify the regexp for t_KEYWORD and fix some problems, the one from r19669
didn't parse "c%" correctly.
Add some more tests.


Modified:
    erp5/trunk/products/ZSQLCatalog/SearchKey/KeyWordKey.py
    erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/KeyWordKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/KeyWordKey.py?rev=19706&r1=19705&r2=19706&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/KeyWordKey.py (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/KeyWordKey.py Wed Mar  5 19:37:53 2008
@@ -101,7 +101,7 @@
     return t
 
   def t_KEYWORD(self, t):
-    r'(%\S*|([^!<>=\s%]\S+|!([^=\s]\S+)?)%)'
+    r'(%\S*|[^!<>=\s%]*%)(?!\S)'
     # KEYWORD must start and/or end with '%'.
     # It may contain arbitrary letters and numbers without white space
     value = t.value.strip()
@@ -155,8 +155,10 @@
         range = '='
         right_side_expression = first_token.value[1:]
       elif first_token.type in ('WORDSET', 'WORD',) and range == 'like':
-        # add trailing and leading '%' to get more results
-        right_side_expression = '%%%s%%' %right_side_expression
+        if '%' not in right_side_expression:
+          # If the search string doesn't already contain '%', add trailing and
+          # leading '%' to get more results
+          right_side_expression = '%%%s%%' % right_side_expression
       query_kw = {key: right_side_expression,
                   'range': range}
       query_list.append(Query(**query_kw))

Modified: erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py?rev=19706&r1=19705&r2=19706&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testZSQLCatalog.py Wed Mar  5 19:37:53 2008
@@ -244,12 +244,22 @@
                             full_text_search_keys=[]))
 
   def testQueryKeywordSearchKeyWithPercent(self):
+    q = Query(title='Fo%oo')
+    self.assertEquals(dict(where_expression="((((title LIKE 'Fo%oo'))))",
+                           select_expression_list=[]),
+          q.asSQLExpression(keyword_search_keys=['title'],))
+
+  def testQueryKeywordSearchKeyWithPercentAndOnlyOneLetter(self):
     q = Query(title='F%o')
-    self.assertEquals(dict(where_expression="((((title LIKE '%F%o%'))))",
-                           select_expression_list=[]),
-          q.asSQLExpression(keyword_search_keys=['title'],
-                            datetime_search_keys = [],
-                            full_text_search_keys=[]))
+    self.assertEquals(dict(where_expression="((((title LIKE 'F%o'))))",
+                           select_expression_list=[]),
+          q.asSQLExpression(keyword_search_keys=['title']))
+
+  def testQueryKeywordSearchKeyWithPercentOnly(self):
+    q = Query(title='%')
+    self.assertEquals(dict(where_expression="((((title LIKE '%'))))",
+                           select_expression_list=[]),
+          q.asSQLExpression(keyword_search_keys=['title'],))
 
   def testQueryKeywordSearchKeyWithMinus(self):
     q = Query(title='F-o')
@@ -266,6 +276,26 @@
           q.asSQLExpression(keyword_search_keys=['title'],
                             datetime_search_keys = [],
                             full_text_search_keys=[]))
+
+  def testQueryKeywordSearchKeyWithPercentAtTheEnd(self):
+    q = Query(title='F%')
+    self.assertEquals(dict(where_expression="((((title LIKE 'F%'))))",
+                           select_expression_list=[]),
+          q.asSQLExpression(keyword_search_keys=['title'],))
+    q = Query(title='Fo%')
+    self.assertEquals(dict(where_expression="((((title LIKE 'Fo%'))))",
+                           select_expression_list=[]),
+          q.asSQLExpression(keyword_search_keys=['title'],))
+
+  def testQueryKeywordSearchKeyWithPercentAtTheBeginning(self):
+    q = Query(title='%o')
+    self.assertEquals(dict(where_expression="((((title LIKE '%o'))))",
+                           select_expression_list=[]),
+          q.asSQLExpression(keyword_search_keys=['title'],))
+    q = Query(title='%oo')
+    self.assertEquals(dict(where_expression="((((title LIKE '%oo'))))",
+                           select_expression_list=[]),
+          q.asSQLExpression(keyword_search_keys=['title'],))
 
   def testNegatedQuery(self):
     q1 = Query(title='Foo')




More information about the Erp5-report mailing list