Commit bf1b4b6d authored by Vincent Pelletier's avatar Vincent Pelletier

Export an API to access SearchKey's parser from SQLCatalog.

Internal use this API too.
Update IQueryCatalog interface.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26856 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1f4b1519
......@@ -214,3 +214,22 @@ class ISearchKeyCatalog(Interface):
False otherwise.
"""
def parseSearchText(search_text, column=None, search_key=None, is_valid=None):
"""
Parses given SearchText expression using given column's parser
(determined by the SearchKey it is configured to use by default), or
given SearchKey name.
search_text (string)
SearchText to parse.
column (string)
Column to use to determine which SearchKey to use for parsing.
Either this parameter or search_key must be provided.
search_key (string)
Name of the SearchKey to use for parsing.
Either this parameter or column must be provided.
if_valid (callback)
Callback method to use to decide wether an encountered column-ish
identifier in SearchText is a valid column.
If not provided, catalog schema will be used.
"""
......@@ -1985,6 +1985,19 @@ class Catalog(Folder,
search_value=result)
return result
def _parseSearchText(self, search_key, search_text, is_valid=None):
if is_valid is None:
is_valid = self.isValidColumn
return search_key.parseSearchText(search_text, is_valid)
def parseSearchText(self, search_text, column=None, search_key=None,
is_valid=None):
if column is None and search_key is None:
raise ValueError, 'One of column and search_key must be different '\
'from None'
return self._parseSearchText(self.getSearchKey(
column, search_key=search_key), search_text, is_valid=is_valid)
@profiler_decorator
def buildQuery(self, kw, ignore_empty_string=True, operator='and'):
query_list = []
......@@ -2036,7 +2049,7 @@ class Catalog(Folder,
# String: parse using key's default search key.
search_key = self.getColumnDefaultSearchKey(key)
if search_key is not None:
abstract_syntax_tree = search_key.parseSearchText(value, self.isValidColumn)
abstract_syntax_tree = self._parseSearchText(search_key, value)
if abstract_syntax_tree is None:
# Parsing failed, create a query from the bare string.
result = self.buildSingleQuery(key, value)
......
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