diff --git a/gen/__init__.py b/gen/__init__.py index e0ac30a..006121d 100644 --- a/gen/__init__.py +++ b/gen/__init__.py @@ -314,8 +314,8 @@ class Search: # use it instead of trying to translate from labels. self.translated = translated self.translatedDescr = translatedDescr - # In the dict below, keys are indexed field names and values are - # search values. + # In the dict below, keys are indexed field names or names of standard + # indexes, and values are search values. self.fields = fields @staticmethod @@ -336,13 +336,14 @@ class Search: return 'get%s%s'% (fieldName[0].upper(),fieldName[1:]) @staticmethod - def getSearchValue(fieldName, fieldValue): + def getSearchValue(fieldName, fieldValue, klass): '''Returns a transformed p_fieldValue for producing a valid search value as required for searching in the index corresponding to p_fieldName.''' - if fieldName in ('title', 'SearchableText'): - # Title and SearchableText are TextIndex indexes. We must split - # p_fieldValue into keywords. + field = getattr(klass, fieldName, None) + if (field and (field.getIndexType() == 'TextIndex')) or \ + (fieldName == 'SearchableText'): + # For TextIndex indexes. We must split p_fieldValue into keywords. res = Keywords(fieldValue).get() elif isinstance(fieldValue, basestring) and fieldValue.endswith('*'): v = fieldValue[:-1] @@ -369,7 +370,7 @@ class Search: res = fieldValue return res - def updateSearchCriteria(self, criteria, advanced=False): + def updateSearchCriteria(self, criteria, klass, advanced=False): '''This method updates dict p_criteria with all the search criteria corresponding to this Search instance. If p_advanced is True, p_criteria correspond to an advanced search, to be stored in the @@ -387,7 +388,8 @@ class Search: if not advanced: attrName = Search.getIndexName(fieldName) # Express the field value in the way needed by the index - criteria[attrName]= Search.getSearchValue(fieldName, fieldValue) + criteria[attrName] = Search.getSearchValue(fieldName, + fieldValue, klass) else: criteria[fieldName]= fieldValue # Add a sort order if specified @@ -821,6 +823,7 @@ class Type: # we consider it to be an index type. It allows to bypass the standard # way to decide what index type must be used. if isinstance(self.indexed, str): return self.indexed + if self.name == 'title': return 'TextIndex' return 'FieldIndex' def getIndexValue(self, obj, forSearch=False): diff --git a/gen/mixins/ToolMixin.py b/gen/mixins/ToolMixin.py index bbd3114..122c24f 100644 --- a/gen/mixins/ToolMixin.py +++ b/gen/mixins/ToolMixin.py @@ -348,12 +348,13 @@ class ToolMixin(BaseMixin): If p_refObject and p_refField are given, the query is limited to the objects that are referenced from p_refObject through p_refField.''' params = {'ClassName': className} + appyClass = self.getAppyClass(className, wrapper=True) if not brainsOnly: params['batch'] = True # Manage additional criteria from a search when relevant if searchName: search = self.getSearch(className, searchName) if search: # Add in params search and sort criteria. - search.updateSearchCriteria(params) + search.updateSearchCriteria(params, appyClass) # Determine or override sort if specified. if sortBy: params['sort_on'] = Search.getIndexName(sortBy, usage='sort') @@ -362,7 +363,7 @@ class ToolMixin(BaseMixin): # If defined, add the filter among search parameters. if filterKey: filterKey = Search.getIndexName(filterKey) - filterValue = Search.getSearchValue(filterKey, filterValue) + filterValue = Search.getSearchValue(filterKey,filterValue,appyClass) params[filterKey] = filterValue # TODO This value needs to be merged with an existing one if already # in params, or, in a first step, we should avoid to display the @@ -372,6 +373,7 @@ class ToolMixin(BaseMixin): params['UID'] = getattr(refObject, refField.name).data # Use index "Allowed" if noSecurity is False if not noSecurity: params['Allowed'] = self.getAllowedValue() + print params brains = self.getPath("/catalog")(**params) if brainsOnly: # Return brains only. @@ -602,9 +604,11 @@ class ToolMixin(BaseMixin): if 'className' not in rq.form: return res klass = self.getAppyClass(rq.form['className']) if not hasattr(klass, 'searchAdvanced'): return res - # In this attribute, we have the Search instance representing automatic - # advanced search criteria. - klass.searchAdvanced.updateSearchCriteria(res, advanced=True) + # In klass.searchAdvanced, we have the Search instance representing + # default advanced search criteria. + wrapperClass = self.getAppyClass(rq.form['className'], wrapper=True) + klass.searchAdvanced.updateSearchCriteria(res, wrapperClass, + advanced=True) return res transformMethods = {'uppercase': 'upper', 'lowercase': 'lower',