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

nobody at svn.erp5.org nobody at svn.erp5.org
Wed May 6 13:58:49 CEST 2009


Author: vincent
Date: Wed May  6 13:58:44 2009
New Revision: 26836

URL: http://svn.erp5.org?rev=26836&view=rev
Log:
When doing multiple FullText lookups in the same SearchText expression, merge all lookups into just one SQL fulltext match (per expression block).
Add a test.

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

Modified: erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py?rev=26836&r1=26835&r2=26836&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/SearchKey/FullTextKey.py [utf8] Wed May  6 13:58:44 2009
@@ -29,9 +29,11 @@
 ##############################################################################
 
 from SearchKey import SearchKey
+from Products.ZSQLCatalog.Query.SimpleQuery import SimpleQuery
 from Products.ZSQLCatalog.SearchText import parse
 from Products.ZSQLCatalog.Interface.ISearchKey import ISearchKey
 from Interface.Verify import verifyClass
+from Products.ZSQLCatalog.SQLCatalog import profiler_decorator
 
 class FullTextKey(SearchKey):
   """
@@ -43,5 +45,21 @@
   def parseSearchText(self, value, is_column):
     return parse(value, is_column)
 
+  @profiler_decorator
+  def _buildQuery(self, operator_value_dict, logical_operator, parsed, group):
+    """
+      Special Query builder for FullText queries: merge all values having the
+      same operator into just one query, to save SQL server from the burden to
+      do multiple fulltext lookups when one would suit the purpose.
+    """
+    column = self.getColumn()
+    query_list = []
+    append = query_list.append
+    for comparison_operator, value_list in operator_value_dict.iteritems():
+      append(SimpleQuery(search_key=self,
+                         comparison_operator=comparison_operator,
+                         group=group, **{column: ' '.join(value_list)}))
+    return query_list
+
 verifyClass(ISearchKey, FullTextKey)
 

Modified: erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py
URL: http://svn.erp5.org/erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py?rev=26836&r1=26835&r2=26836&view=diff
==============================================================================
--- erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] (original)
+++ erp5/trunk/products/ZSQLCatalog/tests/testSQLCatalog.py [utf8] Wed May  6 13:58:44 2009
@@ -394,6 +394,18 @@
     self.assertTrue(self._catalog.isAdvancedSearchText('default:a')) # "default" exists as a column
     self.assertFalse(self._catalog.isAdvancedSearchText('b:a')) # "b" doesn't exist as a column
 
+  def test_FullTextSearchMergesQueries(self):
+    """
+      FullText criterion on the same scope must be merged into one query.
+      Logical operator is ignored, as fulltext operators are expected instead.
+    """
+    self.catalog(ReferenceQuery(ReferenceQuery(operator='match', fulltext='a b'), operator='and'),
+                 {'fulltext': 'a AND b'})
+    self.catalog(ReferenceQuery(ReferenceQuery(operator='match', fulltext='a b'), operator='and'),
+                 {'fulltext': 'a OR b'})
+    self.catalog(ReferenceQuery(ReferenceQuery(ReferenceQuery(operator='match', fulltext='a b'), operator='not'), operator='and'),
+                 {'fulltext': 'NOT (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