diff --git a/product/ZSQLCatalog/Operator/ComparisonOperator.py b/product/ZSQLCatalog/Operator/ComparisonOperator.py index 2a247cccaddeb6ddebfb6857be639f35c47d8e80..acce73b268f1144a10d84273e77ba3cd1bf3f8c7 100644 --- a/product/ZSQLCatalog/Operator/ComparisonOperator.py +++ b/product/ZSQLCatalog/Operator/ComparisonOperator.py @@ -119,7 +119,7 @@ class MatchComparisonOperator(MonovaluedComparisonOperator): select_dict['%s__score__' % column.replace('`', '').rsplit('.', 1)[-1]] = match_string # Support sort on the relevance by using (column)__score__ key. order_by_dict = { - '`%s__score__`' % column.strip('`'): match_string, + '`%s__score__`' % '`.`'.join([x.strip('`') for x in column.split('.')]): match_string, } return SQLExpression( self, diff --git a/product/ZSQLCatalog/SQLExpression.py b/product/ZSQLCatalog/SQLExpression.py index 128bbe6aaec181468ed805cad7094edbdf330257..fcfff1b1416b2bf2bfafec3c91c64bf4bb3cadc8 100644 --- a/product/ZSQLCatalog/SQLExpression.py +++ b/product/ZSQLCatalog/SQLExpression.py @@ -236,6 +236,8 @@ class SQLExpression(object): append = result.append order_by_dict = self._getOrderByDict() for (column, direction, cast) in self.getOrderByList(): + if column.endswith('__score__') and column not in order_by_dict: + continue expression = conflictSafeGet(order_by_dict, column, str(column)) if cast not in (None, ''): expression = 'CAST(%s AS %s)' % (expression, cast)