From 758266ac0868615c45da3a3ab638760c78efa18d Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Mon, 4 May 2009 15:08:44 +0000 Subject: [PATCH] Make SearchText/__init__.py export new "isAdvancedSearchText" function. Export isAdvancedSearchText method on SQLCatalog instance. Document SQLCatalog.isAdvancedSearchText in IQueryCatalog interface. Add a test for new SQLCatalog.isAdvancedSearchText method. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26785 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ZSQLCatalog/Interface/IQueryCatalog.py | 7 +++++++ product/ZSQLCatalog/SQLCatalog.py | 5 +++++ product/ZSQLCatalog/SearchText/SearchTextParser.py | 6 +++++- product/ZSQLCatalog/SearchText/__init__.py | 2 +- product/ZSQLCatalog/tests/testSQLCatalog.py | 6 ++++++ 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/product/ZSQLCatalog/Interface/IQueryCatalog.py b/product/ZSQLCatalog/Interface/IQueryCatalog.py index c569909c07..f9520416ea 100644 --- a/product/ZSQLCatalog/Interface/IQueryCatalog.py +++ b/product/ZSQLCatalog/Interface/IQueryCatalog.py @@ -207,3 +207,10 @@ class ISearchKeyCatalog(Interface): 4- Invoke sql_method """ + + def isAdvancedSearchText(search_text): + """ + Returns True if given value follows Search Text "advanced" syntax, + False otherwise. + """ + diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index e807de6e2b..1acb83d884 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -45,6 +45,8 @@ import md5 from Interface.IQueryCatalog import ISearchKeyCatalog from Interface.Verify import verifyClass +from SearchText import isAdvancedSearchText + PROFILING_ENABLED = False if PROFILING_ENABLED: from tiny_profiler import profiler_decorator, profiler_report, profiler_reset @@ -2267,6 +2269,9 @@ class Catalog(Folder, method = getattr(self, self.sql_count_results) return self.queryResults(method, REQUEST=REQUEST, extra_column_list=self.getCatalogSearchResultKeys(), only_group_columns=True, **kw) + def isAdvancedSearchText(self, search_text): + return isAdvancedSearchText(search_text, self.isValidColumn) + def recordObjectList(self, path_list, catalog=1): """ Record the path of an object being catalogged or uncatalogged. diff --git a/product/ZSQLCatalog/SearchText/SearchTextParser.py b/product/ZSQLCatalog/SearchText/SearchTextParser.py index f795176455..f040c1dbbc 100755 --- a/product/ZSQLCatalog/SearchText/SearchTextParser.py +++ b/product/ZSQLCatalog/SearchText/SearchTextParser.py @@ -65,9 +65,13 @@ def getAdvancedSearchTextParser(): parser_pool.parser = parser return parser +@profiler_decorator +def isAdvancedSearchText(input, is_column): + return getAdvancedSearchTextDetector()(input, is_column) + @profiler_decorator def _parse(input, is_column, *args, **kw): - if getAdvancedSearchTextDetector()(input, is_column): + if isAdvancedSearchText(input, is_column): result = getAdvancedSearchTextParser()(input, *args, **kw) else: result = None diff --git a/product/ZSQLCatalog/SearchText/__init__.py b/product/ZSQLCatalog/SearchText/__init__.py index e45dba662a..8ba00f5ff1 100644 --- a/product/ZSQLCatalog/SearchText/__init__.py +++ b/product/ZSQLCatalog/SearchText/__init__.py @@ -1,2 +1,2 @@ -from SearchTextParser import parse +from SearchTextParser import parse, isAdvancedSearchText diff --git a/product/ZSQLCatalog/tests/testSQLCatalog.py b/product/ZSQLCatalog/tests/testSQLCatalog.py index e3395a0eea..736645b539 100644 --- a/product/ZSQLCatalog/tests/testSQLCatalog.py +++ b/product/ZSQLCatalog/tests/testSQLCatalog.py @@ -388,6 +388,12 @@ class TestSQLCatalog(unittest.TestCase): self.catalog(ReferenceQuery(ReferenceQuery(operator='match', fulltext='a'), operator='and'), {'fulltext': 'a'}) + def test_isAdvancedSearchText(self): + self.assertFalse(self._catalog.isAdvancedSearchText('a')) # No operator, no explicit column + self.assertTrue(self._catalog.isAdvancedSearchText('a AND b')) # "AND" is an operator + 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 + ##return catalog(title=Query(title='a', operator='not')) #return catalog(title={'query': 'a', 'operator': 'not'}) #return catalog(title={'query': ['a', 'b'], 'operator': 'not'}) -- 2.30.9