From 9dddec9cc9a0cfe137ad9d6aa4af78d21177b912 Mon Sep 17 00:00:00 2001 From: Ivan Tyagov <ivan@nexedi.com> Date: Fri, 16 Jul 2010 08:27:41 +0000 Subject: [PATCH] Use portal type based definitions for searchable text generators. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37163 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/Base.py | 26 +++++++++++++++++----- product/ERP5Type/PropertySheet/BaseType.py | 14 ++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py index 32da13608b..82832f9f0a 100644 --- a/product/ERP5Type/Base.py +++ b/product/ERP5Type/Base.py @@ -3196,12 +3196,28 @@ class Base( CopyContainer, ### Content accessor methods security.declareProtected(Permissions.View, 'getSearchableText') def getSearchableText(self, md=None): - """\ - Used by the catalog for basic full text indexing - We should try to do some kind of file conversion here """ - searchable_text = "%s %s %s" % (self.getTitle(), self.getDescription(), - self.getId()) + Used by the catalog for basic full text indexing. + """ + searchable_text_list = [] + portal_type = self.portal_types.getTypeInfo(self) + searchable_text_method_id_list = [] + # generated from properties methods and add explicitly defined method_ids as well + for searchable_text_property_id in portal_type.getSearchableTextPropertyIdList(): + method_id = convertToUpperCase(searchable_text_property_id) + searchable_text_method_id_list.extend(['get%s' %method_id]) + searchable_text_method_id_list.extend(portal_type.getSearchableTextMethodIdList()) + for method_id in searchable_text_method_id_list: + # XXX: how to exclude exclude acquisition (not working) + #if getattr(aq_base(self), method_id, None) is not None: + # method = getattr(self, method_id, None) + # should we do it as ZSQLCatalog should care for calling this method on proper context? + method = getattr(self, method_id, None) + if method is not None: + method_value = method() + if method_value is not None: + searchable_text_list.append(method_value) + searchable_text = ' '.join(searchable_text_list) return searchable_text # Compatibility with CMF Catalog / CPS sites diff --git a/product/ERP5Type/PropertySheet/BaseType.py b/product/ERP5Type/PropertySheet/BaseType.py index cd39bbeadb..e085ed9a6b 100644 --- a/product/ERP5Type/PropertySheet/BaseType.py +++ b/product/ERP5Type/PropertySheet/BaseType.py @@ -100,5 +100,19 @@ class BaseType: , 'label': 'Groups' , 'select_variable':'getAvailableGroupList' }, + # searchable text method id list used by ZSQLCatalog + { 'id': 'searchable_text_property_id' + , 'type': 'lines' + , 'mode': 'w' + , 'label': 'Searchable text property ids' + # default known to exists everythere properties + , 'default': ['title', 'description', 'id', 'reference', 'short_title'] + }, + { 'id': 'searchable_text_method_id' + , 'type': 'lines' + , 'mode': 'w' + , 'label': 'Searchable text method Ids' + , 'default': [] + }, ) -- 2.30.9