Commit 7d7a5f6c authored by Jérome Perrin's avatar Jérome Perrin

catalog: make translated_title behave more like title regarding %

translated_title is used in listbox search columns, so it's very confusing
for users if they can not use the usual % character for partial matches.

This changes the behaviour of translated_title to autodetect the presence of
% and use LIKE comparison operator in such case.
parent b1dfe137
......@@ -141,6 +141,16 @@ class TestContentTranslation(ERP5TypeTestCase):
self.assertEqual(person,
portal.portal_catalog.getResultValue(translated_title='Yusuke'))
# The key also behave like "title" key, ie. we can use % for partial matches
self.assertEqual(person,
portal.portal_catalog.getResultValue(translated_title='Yusu%'))
self.assertEqual(person,
portal.portal_catalog.getResultValue(translated_title='%岡'))
self.assertEqual(person,
portal.portal_catalog.getResultValue(translated_title='%村%'))
self.assertEqual(person,
portal.portal_catalog.getResultValue(translated_title='Yus% OR %oka'))
# Deleting translation should update content_translation table.
person.setNobReadTranslatedFirstName('')
person.setNobReadTranslatedLastName('')
......
from Products.ZSQLCatalog.SQLCatalog import Query, SimpleQuery, AndQuery
from Products.ZSQLCatalog.SQLCatalog import Query, SimpleQuery, AndQuery, ComplexQuery
portal = context.getPortalObject()
# To make `translated_title` behave like `title`, we support the LIKE operator.
# If user made a search with %, we treat it as a LIKE.
operator_value_dict, logical_operator, _ = search_key.processSearchValue(
detect_like=True,
search_value=search_value,
default_logical_operator=logical_operator,
comparison_operator=comparison_operator,
)
if 'like' in operator_value_dict:
return AndQuery(
ComplexQuery(
[
SimpleQuery(
**{
'content_translation.translated_text': search_term,
'comparison_operator': 'like'
}) for search_term in operator_value_dict['like']
],
logical_operator=logical_operator,
),
Query(**{'content_translation.property_name': 'title'}),
)
# This scriptable key supports content_translation if the table is present
catalog = portal.portal_catalog.getSQLCatalog()
if 'content_translation' in catalog.getSqlSearchTablesList():
if [x for x in catalog.getSqlCatalogSearchKeysList() if 'Mroonga' in x]:
return AndQuery(SimpleQuery(**{'content_translation.translated_text': value, 'comparison_operator': 'mroonga_boolean'}),
return AndQuery(SimpleQuery(**{'content_translation.translated_text': search_value, 'comparison_operator': 'mroonga_boolean'}),
Query(**{'content_translation.property_name': 'title'}))
else:
return AndQuery(SimpleQuery(**{'content_translation.translated_text': value, 'comparison_operator': 'match_boolean'}),
return AndQuery(SimpleQuery(**{'content_translation.translated_text': search_value, 'comparison_operator': 'match_boolean'}),
Query(**{'content_translation.property_name': 'title'}))
# Otherwise it simply use title
return Query(title=value)
return Query(title=search_value)
......@@ -50,7 +50,13 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>value</string> </value>
<value> <string>search_value, search_key=None, group=None, logical_operator=None, comparison_operator=None</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
......
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