| ts_rank(to_tsvector, to_tsquery_from_text(%s, 'zh_cn'), 32) AS score | ts_rank(to_tsvector, to_tsquery_from_text(%s, 'zh_cn'), 32) AS score | ||||
| FROM {self.table_name} | FROM {self.table_name} | ||||
| WHERE to_tsvector@@to_tsquery_from_text(%s, 'zh_cn') {where_clause} | WHERE to_tsvector@@to_tsquery_from_text(%s, 'zh_cn') {where_clause} | ||||
| ORDER BY (score,id) DESC | |||||
| ORDER BY score DESC, id DESC | |||||
| LIMIT {top_k}""", | LIMIT {top_k}""", | ||||
| (f"'{query}'", f"'{query}'"), | (f"'{query}'", f"'{query}'"), | ||||
| ) | ) |