Commit 2d2ff6be authored by Yusei Tahara's avatar Yusei Tahara

Add "no-left join" mode to searchPredicateList method. This mode is

enabled only if preferred predicate category list is defined and
all elements in tested_base_category_list parameter are contained in
that preferred value.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36102 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent aaf66a77
......@@ -105,6 +105,7 @@ class DomainTool(BaseTool):
"""
portal_catalog = context.portal_catalog
portal_categories = context.portal_categories
portal_preferences = context.portal_preferences
# Search the columns of the predicate table
column_list = [x.split('.')[1] for x in portal_catalog.getColumnIds()
if x.startswith('predicate.')]
......@@ -186,22 +187,56 @@ class DomainTool(BaseTool):
context.getCategoryMembershipList(tested_base_category, base=1))
if tested_base_category_list != []:
if len(category_list)==0:
category_list = ['NULL']
category_expression_dict = portal_categories.buildAdvancedSQLSelector(
category_list,
query_table='predicate_category',
none_sql_value=0,
strict=strict)
where_expression = category_expression_dict['where_expression']
if where_expression:
sql_kw['where_expression'] = SQLQuery(where_expression)
if 'from_expression' in category_expression_dict:
sql_kw['from_expression'] = category_expression_dict['from_expression']
preferred_predicate_category_list = portal_preferences.getPreferredPredicateCategoryList()
if preferred_predicate_category_list and tested_base_category_list is not None:
# New behavior is enabled only if preferred predicate category is
# defined and tested_base_category_list is passed.
predicate_category_query_list = []
predicate_category_table_name_list = []
for relative_url in category_list:
category_value = portal_categories.getCategoryValue(relative_url)
base_category_value = category_value.getBaseCategory()
if base_category_value.getId() in preferred_predicate_category_list:
table_index = len(predicate_category_query_list)
predicate_category_table_name = 'predicate_category_for_domain_tool_%s' % table_index
table_alias_list = [('predicate_category', predicate_category_table_name)]
predicate_category_query_list.append(
ComplexQuery(
Query(predicate_category_base_category_uid=base_category_value.getUid(), table_alias_list=table_alias_list),
Query(predicate_category_category_strict_membership=1, table_alias_list=table_alias_list),
ComplexQuery(
Query(predicate_category_category_uid=category_value.getUid(), table_alias_list=table_alias_list),
Query(predicate_category_category_uid='NULL', table_alias_list=table_alias_list),
logical_operator='OR'),
logical_operator='AND'))
if not predicate_category_query_list:
# Prevent matching everything
predicate_category_query_list.append(Query(predicate_category_base_category_uid=0))
predicate_category_query = ComplexQuery(
logical_operator='AND',
*predicate_category_query_list)
query_list.append(predicate_category_query)
else:
# Add predicate_category.uid for automatic join
sql_kw['predicate_category.uid'] = '!=NULL'
# Traditional behavior
if len(category_list)==0:
category_list = ['NULL']
category_expression_dict = portal_categories.buildAdvancedSQLSelector(
category_list,
query_table='predicate_category',
none_sql_value=0,
strict=strict)
where_expression = category_expression_dict['where_expression']
if where_expression:
sql_kw['where_expression'] = SQLQuery(where_expression)
if 'from_expression' in category_expression_dict:
sql_kw['from_expression'] = category_expression_dict['from_expression']
else:
# Add predicate_category.uid for automatic join
sql_kw['predicate_category.uid'] = '!=NULL'
kw.update(sql_kw)
if query_list:
......
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