From bf1b4b6df548f42164f2ac28ebf2175e8c521043 Mon Sep 17 00:00:00 2001 From: Vincent Pelletier <vincent@nexedi.com> Date: Wed, 6 May 2009 16:30:41 +0000 Subject: [PATCH] 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 --- .../ZSQLCatalog/Interface/IQueryCatalog.py | 19 +++++++++++++++++++ product/ZSQLCatalog/SQLCatalog.py | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/product/ZSQLCatalog/Interface/IQueryCatalog.py b/product/ZSQLCatalog/Interface/IQueryCatalog.py index f9520416ea..3285a6ef9f 100644 --- a/product/ZSQLCatalog/Interface/IQueryCatalog.py +++ b/product/ZSQLCatalog/Interface/IQueryCatalog.py @@ -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. + """ diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index 1acb83d884..771be48549 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -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) -- 2.30.9