Commit 3438bad5 authored by Jérome Perrin's avatar Jérome Perrin

Only index a property in full text if document has the property

parent 083357b2
...@@ -892,6 +892,19 @@ class TestDocument(TestDocumentMixin): ...@@ -892,6 +892,19 @@ class TestDocument(TestDocumentMixin):
web_page.getReference(), web_page.getReference(),
web_page.getLanguage(), web_page.getLanguage(),
web_page.getVersion()))) web_page.getVersion())))
document = portal.document_module.newContent(
portal_type = 'Presentation',)
# searchable text is empty by default
self.assertEquals('', document.SearchableText())
# it contains title
document.setTitle('foo')
self.assertEquals('foo', document.SearchableText())
# and description
document.setDescription('bar')
self.assertTrue('bar' in document.SearchableText(),
document.SearchableText())
def test_10_SearchString(self): def test_10_SearchString(self):
""" """
Test search string search generation and parsing. Test search string search generation and parsing.
......
...@@ -3020,10 +3020,13 @@ class Base( CopyContainer, ...@@ -3020,10 +3020,13 @@ class Base( CopyContainer,
# so use definition of 'Base Type' for searchable methods & properties # so use definition of 'Base Type' for searchable methods & properties
portal_type = self.portal_types.getTypeInfo('Base Type') portal_type = self.portal_types.getTypeInfo('Base Type')
searchable_text_method_id_list = [] searchable_text_method_id_list = []
# generated from properties methods and add explicitly defined method_ids as well # generated from properties methods and add explicitly defined method_ids as well
for searchable_text_property_id in portal_type.getSearchableTextPropertyIdList(): for searchable_text_property_id in portal_type.getSearchableTextPropertyIdList():
method_id = convertToUpperCase(searchable_text_property_id) if self.hasProperty(searchable_text_property_id):
searchable_text_method_id_list.extend(['get%s' %method_id]) 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()) searchable_text_method_id_list.extend(portal_type.getSearchableTextMethodIdList())
for method_id in searchable_text_method_id_list: for method_id in searchable_text_method_id_list:
# XXX: how to exclude exclude acquisition (not working) # XXX: how to exclude exclude acquisition (not working)
...@@ -3039,7 +3042,7 @@ class Base( CopyContainer, ...@@ -3039,7 +3042,7 @@ class Base( CopyContainer,
else: else:
searchable_text_list.append(method_value) searchable_text_list.append(method_value)
searchable_text = ' '.join([str(x) for x in searchable_text_list]) searchable_text = ' '.join([str(x) for x in searchable_text_list])
return searchable_text return searchable_text.strip()
# Compatibility with CMF Catalog / CPS sites # Compatibility with CMF Catalog / CPS sites
SearchableText = getSearchableText SearchableText = getSearchableText
......
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