Commit a2759acd authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Include table name in fulltext search score's alias.

so that group_by_list or order_by_list using 'full_text.SearchableText__score__' works.
parent 89e13319
...@@ -453,7 +453,10 @@ class ColumnMap(object): ...@@ -453,7 +453,10 @@ class ColumnMap(object):
def asSQLColumn(self, raw_column, group=DEFAULT_GROUP_ID): def asSQLColumn(self, raw_column, group=DEFAULT_GROUP_ID):
if self.catalog_table_name is None or raw_column in self.column_ignore_set or \ if self.catalog_table_name is None or raw_column in self.column_ignore_set or \
'.' in raw_column or '*' in raw_column: '.' in raw_column or '*' in raw_column:
result = raw_column if raw_column.endswith('__score__'):
result = raw_column.replace('.', '_')
else:
result = raw_column
else: else:
if raw_column.endswith('__score__'): if raw_column.endswith('__score__'):
raw_column = raw_column[:-9] raw_column = raw_column[:-9]
...@@ -464,7 +467,10 @@ class ColumnMap(object): ...@@ -464,7 +467,10 @@ class ColumnMap(object):
if group is DEFAULT_GROUP_ID: if group is DEFAULT_GROUP_ID:
group, column = self.related_key_dict.get(column, (group, raw_column)) group, column = self.related_key_dict.get(column, (group, raw_column))
alias = self.table_alias_dict[(group, self.column_map[(group, column)])] alias = self.table_alias_dict[(group, self.column_map[(group, column)])]
result = '`%s`.`%s%s`' % (alias, column, column_suffix) if column_suffix:
result = '%s_%s%s' % (alias, column, column_suffix)
else:
result = '`%s`.`%s`' % (alias, column)
if function is not None: if function is not None:
result = '%s(%s)' % (function, result) result = '%s(%s)' % (function, result)
return result return result
......
...@@ -116,16 +116,11 @@ class MatchComparisonOperator(MonovaluedComparisonOperator): ...@@ -116,16 +116,11 @@ class MatchComparisonOperator(MonovaluedComparisonOperator):
} }
select_dict = {} select_dict = {}
if not only_group_columns: if not only_group_columns:
select_dict['%s__score__' % column.replace('`', '').rsplit('.', 1)[-1]] = match_string select_dict['%s__score__' % column.replace('`', '').replace('.', '_')] = match_string
# Support sort on the relevance by using (column)__score__ key.
order_by_dict = {
'`%s__score__`' % '`.`'.join([x.strip('`') for x in column.split('.')]): match_string,
}
return SQLExpression( return SQLExpression(
self, self,
select_dict=select_dict, select_dict=select_dict,
where_expression=match_string, where_expression=match_string,
order_by_dict=order_by_dict,
can_merge_select_dict=True, can_merge_select_dict=True,
) )
......
...@@ -238,8 +238,6 @@ class SQLExpression(object): ...@@ -238,8 +238,6 @@ class SQLExpression(object):
append = result.append append = result.append
order_by_dict = self._getOrderByDict() order_by_dict = self._getOrderByDict()
for (column, direction, cast) in self.getOrderByList(): 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)) expression = conflictSafeGet(order_by_dict, column, str(column))
expression = self._reversed_select_dict.get(expression, expression) expression = self._reversed_select_dict.get(expression, expression)
if cast not in (None, ''): if cast not in (None, ''):
......
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