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

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jun 2 14:32:30 CEST 2009


Author: vincent
Date: Tue Jun  2 14:32:28 2009
New Revision: 27335

URL: http://svn.erp5.org?rev=27335&view=rev
Log:
Add FullText bolean mode detection heuristic.
Add a test.
FullText operators have no SearchText representation, so disable it explicitely.

Modified:
    erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py
    erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py
    erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py

Modified: erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py?rev=27335&r1=27334&r2=27335&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/Operator/ComparisonOperator.py [utf8] Tue Jun  2 14:32:28 2009
@@ -100,7 +100,7 @@
 
 class MatchComparisonOperator(MonovaluedComparisonOperator):
   def __init__(self, operator, mode=''):
-    MonovaluedComparisonOperator.__init__(self, operator)
+    MonovaluedComparisonOperator.__init__(self, operator, '')
     self.where_expression_format_string = 'MATCH (%%(column)s) AGAINST (%%(value_list)s%s)' % (mode, )
 
   @profiler_decorator

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py?rev=27335&r1=27334&r2=27335&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py [utf8] Tue Jun  2 14:32:28 2009
@@ -34,6 +34,9 @@
 from Products.ZSQLCatalog.interfaces.search_key import ISearchKey
 from Interface.Verify import verifyClass
 from Products.ZSQLCatalog.SQLCatalog import profiler_decorator
+import re
+
+FULLTEXT_BOLLEAN_DETECTOR = re.compile(r'.*[\+\-<>\(\)\~\*]')
 
 class FullTextKey(SearchKey):
   """
@@ -44,6 +47,29 @@
 
   def parseSearchText(self, value, is_column):
     return parse(value, is_column)
+
+  @profiler_decorator
+  def _processSearchValue(self, search_value, logical_operator,
+                          comparison_operator):
+    """
+      Special SearchValue processor for FullText queries: if a searched value
+      from 'match' operator group contains an operator recognised in boolean
+      mode, make the operator for that value be 'match_boolean'.
+    """
+    operator_value_dict, logical_operator, parsed = \
+      SearchKey._processSearchValue(self, search_value, logical_operator,
+                                    comparison_operator)
+    new_value_list = []
+    append = new_value_list.append
+    for value in operator_value_dict.pop('match', []):
+      if isinstance(value, basestring) and \
+         FULLTEXT_BOLLEAN_DETECTOR.match(value) is not None:
+        operator_value_dict.setdefault('match_boolean', []).append(value)
+      else:
+        append(value)
+    if len(new_value_list):
+      operator_value_dict['match'] = new_value_list
+    return operator_value_dict, logical_operator, parsed
 
   @profiler_decorator
   def _buildQuery(self, operator_value_dict, logical_operator, parsed, group):

Modified: erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py?rev=27335&r1=27334&r2=27335&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] Tue Jun  2 14:32:28 2009
@@ -422,6 +422,14 @@
     self.assertRaises(ValueError, SimpleQuery, default=None, comparison_operator='>=')
     self.assertRaises(ValueError, SimpleQuery, default=1, comparison_operator='is')
 
+  def test_FullTextBooleanMode(self):
+    """
+      Fulltext searches must switch automatically to boolean mode if boolean
+      operators are found in search value.
+    """
+    self.catalog(ReferenceQuery(ReferenceQuery(operator='match_boolean', fulltext='a+b'), operator='and'),
+                 {'fulltext': 'a+b'})
+
 ##return catalog(title=Query(title='a', operator='not'))
 #return catalog(title={'query': 'a', 'operator': 'not'})
 #return catalog(title={'query': ['a', 'b'], 'operator': 'not'})




More information about the Erp5-report mailing list