Commit 758266ac authored by Vincent Pelletier's avatar Vincent Pelletier

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
parent 76f8f4b8
......@@ -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.
"""
......@@ -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.
......
......@@ -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
......
from SearchTextParser import parse
from SearchTextParser import parse, isAdvancedSearchText
......@@ -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'})
......
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