Commit 10e171cb authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

fixup! support sort on both the full text search score and the column value itself.

* ignore sort on full text search score if no full text search happens.
* escape table name and column name in order_by_dict.
parent 06bf634f
......@@ -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,
......
......@@ -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)
......
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